class TwitterCldr::Resources::ListFormats
Attributes
cldr_req[R]
locale[R]
Public Class Methods
new(locale, cldr_req)
click to toggle source
# File lib/twitter_cldr/resources/list_formats_importer.rb, line 79 def initialize(locale, cldr_req) @locale = locale @cldr_req = cldr_req end
Public Instance Methods
cldr_main_path()
click to toggle source
# File lib/twitter_cldr/resources/list_formats_importer.rb, line 133 def cldr_main_path @cldr_main_path ||= File.join(cldr_req.common_path, 'main') end
doc()
click to toggle source
# File lib/twitter_cldr/resources/list_formats_importer.rb, line 126 def doc @doc ||= begin locale_fs = locale.to_s.gsub('-', '_') Nokogiri.XML(File.read(File.join(cldr_main_path, "#{locale_fs}.xml"))) end end
lists()
click to toggle source
# File lib/twitter_cldr/resources/list_formats_importer.rb, line 88 def lists doc.xpath('//ldml/listPatterns/listPattern').each_with_object({}) do |pattern_node, pattern_result| pattern_type = if attribute = pattern_node.attribute('type') attribute.value.to_sym else :default end pattern_node = pattern_for(pattern_type) pattern_result[pattern_type] = pattern_node.xpath('listPatternPart').each_with_object({}) do |type_node, type_result| type_result[type_node.attribute('type').value.to_sym] = type_node.content end end end
pattern_for(type)
click to toggle source
# File lib/twitter_cldr/resources/list_formats_importer.rb, line 104 def pattern_for(type) xpath = xpath_for(type) pattern_node = doc.xpath(xpath)[0] alias_node = pattern_node.xpath('alias')[0] if alias_node alias_type = alias_node.attribute('path').value[/@type='([\w-]+)'/, 1] || :default # follow aliases so we can fully expand them pattern_node = pattern_for(alias_type) end pattern_node end
to_h()
click to toggle source
# File lib/twitter_cldr/resources/list_formats_importer.rb, line 84 def to_h { lists: lists } end
xpath_for(type)
click to toggle source
# File lib/twitter_cldr/resources/list_formats_importer.rb, line 118 def xpath_for(type) if type == :default '//ldml/listPatterns/listPattern[not(@type)]' else "//ldml/listPatterns/listPattern[@type='#{type}']" end end