Module: TagMixin

Included in:
TagBuilder::TagBwCd, TagBuilder::TagInCd
Defined in:
lib/tag_builder/tag_mixin.rb

Overview

Copyright © 2016-2024, Claudio Bustos Navarrete All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  • Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. TagMixin for common methods on tags for cd and tags for relation between cd

Alternatives: Maybe a Delegator pattern should work. All tag related actions are managed by a common Class (TagBuilder) and the differences between cd tags and relations tags are mannaged by a object inside the class

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



35
36
37
# File 'lib/tag_builder/tag_mixin.rb', line 35

def id
  @id
end

#negativosObject (readonly)

Returns the value of attribute negativos.



35
36
37
# File 'lib/tag_builder/tag_mixin.rb', line 35

def negativos
  @negativos
end

#positivosObject (readonly)

Returns the value of attribute positivos.



35
36
37
# File 'lib/tag_builder/tag_mixin.rb', line 35

def positivos
  @positivos
end

#predeterminadoObject

Returns the value of attribute predeterminado.



36
37
38
# File 'lib/tag_builder/tag_mixin.rb', line 36

def predeterminado
  @predeterminado
end

#textObject (readonly)

Returns the value of attribute text.



35
36
37
# File 'lib/tag_builder/tag_mixin.rb', line 35

def text
  @text
end

Instance Method Details

#button_negative_html(ru) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/tag_builder/tag_mixin.rb', line 81

def button_negative_html(ru)
  if ru.nil? or ru[:decision]=='yes'
    button_change_html(:reject, :minus, negativos)
  else
    button_same_html(:danger, :minus, negativos)
  end
end

#button_positive_html(ru) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/tag_builder/tag_mixin.rb', line 73

def button_positive_html(ru)
  if ru.nil? or ru[:decision]=='no'
    button_change_html(:approve, :plus, positivos)
  else
    button_same_html(:success, :plus, positivos)
  end
end

#button_same_html(btn_class, glyphicon_class, number) ⇒ Object



69
70
71
# File 'lib/tag_builder/tag_mixin.rb', line 69

def button_same_html(btn_class, glyphicon_class, number)
  "<button class='btn btn-#{btn_class}'><span class='glyphicon glyphicon-#{glyphicon_class}'></span> <span class='badge '>#{number}</span></button>"
end

#buttons_html(user_id) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/tag_builder/tag_mixin.rb', line 48

def buttons_html(user_id)
  ru = resultado_usuario(user_id)
  "
<div class='btn-group btn-group-xs'>
#{button_positive_html(ru)}
  #{button_negative_html(ru)}
</div>"
end

#initialize_common(votos) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/tag_builder/tag_mixin.rb', line 38

def initialize_common(votos)
  @votos=votos
  @positivos=votos.count {|v| v[:decision]=='yes'}
  @negativos=votos.count {|v| v[:decision]=='no'}
  @id=votos[0][:id]
  @text=votos[0][:text]
  @rs_id=votos[0][:systematic_review_id]
  @tag_id=votos[0][:tag_id]
end

#mostrarObject



65
66
67
# File 'lib/tag_builder/tag_mixin.rb', line 65

def mostrar
  @predeterminado or @positivos > 0
end

#resultado_usuario(user_id) ⇒ Object



57
58
59
# File 'lib/tag_builder/tag_mixin.rb', line 57

def resultado_usuario(user_id)
  @votos.find {|v| v[:user_id] == user_id}
end

#sin_votos?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/tag_builder/tag_mixin.rb', line 61

def sin_votos?
  positivos + negativos == 0
end