Class: TwitterCldr::Resources::CldrDocumentSet
- Inherits:
-
Object
- Object
- TwitterCldr::Resources::CldrDocumentSet
- Defined in:
- lib/twitter_cldr/resources/cldr_document_set.rb
Defined Under Namespace
Classes: Element, ElementList
Instance Attribute Summary collapse
-
#cldr_locale ⇒ Object
readonly
Returns the value of attribute cldr_locale.
-
#cldr_requirement ⇒ Object
readonly
Returns the value of attribute cldr_requirement.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(path, cldr_locale, cldr_requirement) ⇒ CldrDocumentSet
constructor
A new instance of CldrDocumentSet.
- #path_for(node) ⇒ Object
- #xpath(path) ⇒ Object
Constructor Details
#initialize(path, cldr_locale, cldr_requirement) ⇒ CldrDocumentSet
Returns a new instance of CldrDocumentSet.
78 79 80 81 82 |
# File 'lib/twitter_cldr/resources/cldr_document_set.rb', line 78 def initialize(path, cldr_locale, cldr_requirement) @path = path @cldr_locale = cldr_locale @cldr_requirement = cldr_requirement end |
Instance Attribute Details
#cldr_locale ⇒ Object (readonly)
Returns the value of attribute cldr_locale.
76 77 78 |
# File 'lib/twitter_cldr/resources/cldr_document_set.rb', line 76 def cldr_locale @cldr_locale end |
#cldr_requirement ⇒ Object (readonly)
Returns the value of attribute cldr_requirement.
76 77 78 |
# File 'lib/twitter_cldr/resources/cldr_document_set.rb', line 76 def cldr_requirement @cldr_requirement end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
76 77 78 |
# File 'lib/twitter_cldr/resources/cldr_document_set.rb', line 76 def path @path end |
Class Method Details
.join_xpaths(*paths) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/twitter_cldr/resources/cldr_document_set.rb', line 64 def self.join_xpaths(*paths) segments = paths.flat_map { |a| a.chomp('/').split('/') } segments = segments.each_with_object([]) do |segment, result| if segment == '..' result.pop else result << segment end end segments.join('/') end |
Instance Method Details
#path_for(node) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/twitter_cldr/resources/cldr_document_set.rb', line 97 def path_for(node) orig_node = node path = [] while node path << selector_for(node) node = node.parent break if node.name == 'document' end "//#{path.reverse.join('/')}" end |
#xpath(path) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/twitter_cldr/resources/cldr_document_set.rb', line 85 def xpath(path) cldr_locale.ancestors.each do |ancestor_locale| data = doc_for(ancestor_locale).xpath(path) unless data.empty? return ElementList.new(self, resolve_aliases_in(data)) end end ElementList.new(self, []) end |