Class: MESH::Heading

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/MESH/heading.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



5
6
7
# File 'lib/MESH/heading.rb', line 5

def children
  @children
end

#default_localeObject

Returns the value of attribute default_locale.



5
6
7
# File 'lib/MESH/heading.rb', line 5

def default_locale
  @default_locale
end

#descriptor_classObject

Returns the value of attribute descriptor_class.



5
6
7
# File 'lib/MESH/heading.rb', line 5

def descriptor_class
  @descriptor_class
end

#linkified_summaryObject (readonly)

Returns the value of attribute linkified_summary.



6
7
8
# File 'lib/MESH/heading.rb', line 6

def linkified_summary
  @linkified_summary
end

#parentsObject

Returns the value of attribute parents.



5
6
7
# File 'lib/MESH/heading.rb', line 5

def parents
  @parents
end

#rootsObject

Returns the value of attribute roots.



5
6
7
# File 'lib/MESH/heading.rb', line 5

def roots
  @roots
end

#semantic_typesObject

Returns the value of attribute semantic_types.



5
6
7
# File 'lib/MESH/heading.rb', line 5

def semantic_types
  @semantic_types
end

#tree_numbersObject

Returns the value of attribute tree_numbers.



5
6
7
# File 'lib/MESH/heading.rb', line 5

def tree_numbers
  @tree_numbers
end

#unique_idObject

Returns the value of attribute unique_id.



5
6
7
# File 'lib/MESH/heading.rb', line 5

def unique_id
  @unique_id
end

#usefulObject

Returns the value of attribute useful.



5
6
7
# File 'lib/MESH/heading.rb', line 5

def useful
  @useful
end

Returns the value of attribute wikipedia_links.



5
6
7
# File 'lib/MESH/heading.rb', line 5

def wikipedia_links
  @wikipedia_links
end

Instance Method Details

#<=>(other) ⇒ Object



8
9
10
# File 'lib/MESH/heading.rb', line 8

def <=> other
  self.unique_id <=> other.unique_id
end

#deepest_position(root = '') ⇒ Object



56
57
58
59
60
# File 'lib/MESH/heading.rb', line 56

def deepest_position(root = '')
  return nil if tree_numbers.empty?
  deepest_tree_number = tree_numbers.max_by { |tn| tn.start_with?(root) ? tn.length : 0 }
  deepest_tree_number.split('.').length
end

#entries(locale = default_locale) ⇒ Object



32
33
34
# File 'lib/MESH/heading.rb', line 32

def entries(locale = default_locale)
  @entries[locale] ||= []
end

#has_ancestor(heading) ⇒ Object



37
38
39
40
41
42
# File 'lib/MESH/heading.rb', line 37

def has_ancestor(heading)
  return false if parents.empty?
  return true if parents.include? heading
  in_grandparents = parents.map { |p| p.has_ancestor(heading) }
  return in_grandparents.include? true
end

#has_descendant(heading) ⇒ Object



44
45
46
47
48
49
# File 'lib/MESH/heading.rb', line 44

def has_descendant(heading)
  return false if children.empty?
  return true if children.include? heading
  in_grandchildren = children.map { |p| p.has_descendant(heading) }
  return in_grandchildren.include? true
end

#inspectObject



88
89
90
# File 'lib/MESH/heading.rb', line 88

def inspect
  to_s
end

#linkify_summaryObject



24
25
26
27
28
29
30
# File 'lib/MESH/heading.rb', line 24

def linkify_summary
  return if summary.nil?
  @linkified_summary = summary.gsub(/[A-Z]+[A-Z,\s-]+[A-Z]+/).each do |text|
    heading = @tree.find_by_entry(text)
    heading ? yield(text, heading) : text
  end
end

#matches(conditions) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/MESH/heading.rb', line 68

def matches(conditions)
  conditions.each do |field, pattern|
    field_content = self.send(field)
    if field_content.kind_of?(Array)
      return false unless field_content.find { |fc| pattern =~ fc }
    elsif field_content.is_a?(TrueClass) || field_content.is_a?(FalseClass)
      return false unless field_content == pattern
    elsif field_content.is_a? Symbol
      return field_content == pattern
    else
      return false unless pattern =~ field_content
    end
  end
  return true
end

#natural_language_name(locale = default_locale) ⇒ Object



16
17
18
# File 'lib/MESH/heading.rb', line 16

def natural_language_name(locale = default_locale)
  @natural_language_name[locale]
end

#original_heading(locale = default_locale) ⇒ Object



12
13
14
# File 'lib/MESH/heading.rb', line 12

def original_heading(locale = default_locale)
  @original_heading[locale]
end

#set_natural_language_name(name, locale = default_locale) ⇒ Object



96
97
98
# File 'lib/MESH/heading.rb', line 96

def set_natural_language_name(name, locale = default_locale)
  @natural_language_name[locale] = name
end

#set_original_heading(heading, locale = default_locale) ⇒ Object



92
93
94
# File 'lib/MESH/heading.rb', line 92

def set_original_heading(heading, locale = default_locale)
  @original_heading[locale] = heading
end

#set_summary(summary, locale = default_locale) ⇒ Object



100
101
102
# File 'lib/MESH/heading.rb', line 100

def set_summary(summary, locale = default_locale)
  @summary[locale] = summary
end

#shallowest_positionObject



62
63
64
65
66
# File 'lib/MESH/heading.rb', line 62

def shallowest_position
  return nil if tree_numbers.empty?
  shallowest_tree_number = tree_numbers.min_by { |tn| tn.length }
  shallowest_tree_number.split('.').length
end

#sibling?(heading) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
54
# File 'lib/MESH/heading.rb', line 51

def sibling?(heading)
  common_parents = parents & heading.parents
  !common_parents.empty?
end

#summary(locale = default_locale) ⇒ Object



20
21
22
# File 'lib/MESH/heading.rb', line 20

def summary(locale = default_locale)
  @summary[locale]
end

#to_sObject



84
85
86
# File 'lib/MESH/heading.rb', line 84

def to_s
  "#{unique_id}, #{original_heading}, [#{tree_numbers.join(',')}]"
end