Class: TagBuilder::ContainerTagInCd

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/tag_builder/container_tag_in_cd.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(revision, cd) ⇒ ContainerTagInCd

Returns a new instance of ContainerTagInCd



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/tag_builder/container_tag_in_cd.rb', line 33

def initialize(revision,cd)

  @review=revision
  @cd=cd
  # Tags ya elegidos
  @tag_cd_rs=::TagInCd.tags_rs_cd(revision,cd).to_hash_groups(:tag_id)
  # Ahora, los tags por defecto que falta por elegir
  @predeterminados=[]

  @review.t_clases_documentos.each do |clase|
    clase.tags.each do |tag|
      @predeterminados.push(tag.id)
      unless @tag_cd_rs.keys.include? tag.id
        @tag_cd_rs[tag.id]=[{:systematic_review_id=>revision.id, :canonical_document_id=>cd.id,:tag_id=>tag.id,:text=>tag.text,:user_id=>0,:decision=>nil}]
      end
    end
  end
end

Instance Attribute Details

#tag_cd_rsObject (readonly)

Returns the value of attribute tag_cd_rs



32
33
34
# File 'lib/tag_builder/container_tag_in_cd.rb', line 32

def tag_cd_rs
  @tag_cd_rs
end

Instance Method Details

#eachObject



64
65
66
67
68
69
70
# File 'lib/tag_builder/container_tag_in_cd.rb', line 64

def each
  tags_orderados.each do |v|
    recs=::TagBuilder::TagInCd.new(v[1])
    recs.predeterminado=@predeterminados.include? v[0]
    yield recs
  end
end

#tags_orderadosObject



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/tag_builder/container_tag_in_cd.rb', line 51

def tags_orderados
  @tag_cd_rs.sort {|a,b|
    tag_1=a[1][0]
    tag_2=b[1][0]
    if @predeterminados.include? tag_1[:tag_id] and !@predeterminados.include? tag_2[:tag_id]
      +1
    elsif !@predeterminados.include? tag_1[:tag_id] and @predeterminados.include? tag_2[:tag_id]
      -1
    else
      tag_1[:text]<=>tag_2[:text]
    end
  }
end