Class: MESH::Heading
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#default_locale ⇒ Object
Returns the value of attribute default_locale.
-
#descriptor_class ⇒ Object
Returns the value of attribute descriptor_class.
-
#linkified_summary ⇒ Object
readonly
Returns the value of attribute linkified_summary.
-
#parents ⇒ Object
Returns the value of attribute parents.
-
#roots ⇒ Object
Returns the value of attribute roots.
-
#semantic_types ⇒ Object
Returns the value of attribute semantic_types.
-
#structured_entries ⇒ Object
Returns the value of attribute structured_entries.
-
#tree_numbers ⇒ Object
Returns the value of attribute tree_numbers.
-
#unique_id ⇒ Object
Returns the value of attribute unique_id.
-
#useful ⇒ Object
Returns the value of attribute useful.
-
#wikipedia_links ⇒ Object
Returns the value of attribute wikipedia_links.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #deepest_position(root = '') ⇒ Object
- #entries(locale = default_locale) ⇒ Object
- #has_ancestor(heading) ⇒ Object
- #has_descendant(heading) ⇒ Object
- #inspect ⇒ Object
- #linkify_summary ⇒ Object
- #matches(conditions) ⇒ Object
- #natural_language_name(locale = default_locale) ⇒ Object
- #original_heading(locale = default_locale) ⇒ Object
- #set_natural_language_name(name, locale = default_locale) ⇒ Object
- #set_original_heading(heading, locale = default_locale) ⇒ Object
- #set_summary(summary, locale = default_locale) ⇒ Object
- #shallowest_position ⇒ Object
- #sibling?(heading) ⇒ Boolean
- #summary(locale = default_locale) ⇒ Object
- #to_s ⇒ Object
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
5 6 7 |
# File 'lib/MESH/heading.rb', line 5 def children @children end |
#default_locale ⇒ Object
Returns the value of attribute default_locale.
5 6 7 |
# File 'lib/MESH/heading.rb', line 5 def default_locale @default_locale end |
#descriptor_class ⇒ Object
Returns the value of attribute descriptor_class.
5 6 7 |
# File 'lib/MESH/heading.rb', line 5 def descriptor_class @descriptor_class end |
#linkified_summary ⇒ Object (readonly)
Returns the value of attribute linkified_summary.
6 7 8 |
# File 'lib/MESH/heading.rb', line 6 def linkified_summary @linkified_summary end |
#parents ⇒ Object
Returns the value of attribute parents.
5 6 7 |
# File 'lib/MESH/heading.rb', line 5 def parents @parents end |
#roots ⇒ Object
Returns the value of attribute roots.
5 6 7 |
# File 'lib/MESH/heading.rb', line 5 def roots @roots end |
#semantic_types ⇒ Object
Returns the value of attribute semantic_types.
5 6 7 |
# File 'lib/MESH/heading.rb', line 5 def semantic_types @semantic_types end |
#structured_entries ⇒ Object
Returns the value of attribute structured_entries.
5 6 7 |
# File 'lib/MESH/heading.rb', line 5 def structured_entries @structured_entries end |
#tree_numbers ⇒ Object
Returns the value of attribute tree_numbers.
5 6 7 |
# File 'lib/MESH/heading.rb', line 5 def tree_numbers @tree_numbers end |
#unique_id ⇒ Object
Returns the value of attribute unique_id.
5 6 7 |
# File 'lib/MESH/heading.rb', line 5 def unique_id @unique_id end |
#useful ⇒ Object
Returns the value of attribute useful.
5 6 7 |
# File 'lib/MESH/heading.rb', line 5 def useful @useful end |
#wikipedia_links ⇒ Object
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
55 56 57 58 59 |
# File 'lib/MESH/heading.rb', line 55 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
36 37 38 39 40 41 |
# File 'lib/MESH/heading.rb', line 36 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
43 44 45 46 47 48 |
# File 'lib/MESH/heading.rb', line 43 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 |
#inspect ⇒ Object
87 88 89 |
# File 'lib/MESH/heading.rb', line 87 def inspect to_s end |
#linkify_summary ⇒ Object
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
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/MESH/heading.rb', line 67 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
95 96 97 |
# File 'lib/MESH/heading.rb', line 95 def set_natural_language_name(name, locale = default_locale) @natural_language_name[locale] = name end |
#set_original_heading(heading, locale = default_locale) ⇒ Object
91 92 93 |
# File 'lib/MESH/heading.rb', line 91 def set_original_heading(heading, locale = default_locale) @original_heading[locale] = heading end |
#set_summary(summary, locale = default_locale) ⇒ Object
99 100 101 |
# File 'lib/MESH/heading.rb', line 99 def set_summary(summary, locale = default_locale) @summary[locale] = summary end |
#shallowest_position ⇒ Object
61 62 63 64 65 |
# File 'lib/MESH/heading.rb', line 61 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
50 51 52 53 |
# File 'lib/MESH/heading.rb', line 50 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_s ⇒ Object
83 84 85 |
# File 'lib/MESH/heading.rb', line 83 def to_s "#{unique_id}, #{original_heading}, [#{tree_numbers.join(',')}]" end |