Class: TagBuilder::ContainerTagBwCd

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

Overview

Container for tags between canonical documents

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(revision, cd_start, cd_end) ⇒ ContainerTagBwCd

Returns a new instance of ContainerTagBwCd



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/tag_builder/container_tag_bw_cd.rb', line 35

def initialize(revision,cd_start, cd_end)

  @review = revision
  @cd_start = cd_start
  @cd_end   = cd_end
  # Tags ya elegidos
  @tag_cd_rs_ref=::TagBwCd.tags_rs_cd(revision,cd_start, cd_end).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_ref.keys.include? tag.id
        @tag_cd_rs_ref[tag.id]=[{:systematic_review_id=>revision.id, :cd_start=>cd_start.id, cd_end=>cd_end.id, :tag_id=>tag.id,:text=>tag.text,:user_id=>0,:decision=>nil}]
      end
    end
  end
end

Instance Attribute Details

#tag_cd_rs_refObject (readonly)

Returns the value of attribute tag_cd_rs_ref



34
35
36
# File 'lib/tag_builder/container_tag_bw_cd.rb', line 34

def tag_cd_rs_ref
  @tag_cd_rs_ref
end

Instance Method Details

#eachObject



69
70
71
72
73
74
75
# File 'lib/tag_builder/container_tag_bw_cd.rb', line 69

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

#tags_orderadosObject



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/tag_builder/container_tag_bw_cd.rb', line 55

def tags_orderados
  @tag_cd_rs_ref.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