Class: Globalize::Locale::LanguageTag
- Inherits:
-
Struct
- Object
- Struct
- Globalize::Locale::LanguageTag
- Defined in:
- lib/globalize/locale/language_tag.rb
Defined Under Namespace
Modules: SimpleParser
Class Method Summary collapse
Instance Method Summary collapse
- #parent ⇒ Object
- #parents(include_self = true) ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
- #to_sym ⇒ Object
Class Method Details
.parser ⇒ Object
14 15 16 |
# File 'lib/globalize/locale/language_tag.rb', line 14 def parser @@parser ||= SimpleParser end |
.parser=(parser) ⇒ Object
18 19 20 |
# File 'lib/globalize/locale/language_tag.rb', line 18 def parser=(parser) @@parser = parser end |
.tag(tag) ⇒ Object
22 23 24 25 |
# File 'lib/globalize/locale/language_tag.rb', line 22 def tag(tag) matches = parser.match(tag) new *matches if matches end |
Instance Method Details
#parent ⇒ Object
44 45 46 47 |
# File 'lib/globalize/locale/language_tag.rb', line 44 def parent segs = to_a.compact segs.length < 2 ? nil : LanguageTag.tag(segs[0..(segs.length-2)].join('-')) end |
#parents(include_self = true) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/globalize/locale/language_tag.rb', line 49 def parents(include_self = true) result, parent = [], self.dup result << parent if include_self while parent = parent.parent result << parent end result end |
#to_a ⇒ Object
40 41 42 |
# File 'lib/globalize/locale/language_tag.rb', line 40 def to_a members.collect {|attr| self.send(attr) } end |
#to_s ⇒ Object
36 37 38 |
# File 'lib/globalize/locale/language_tag.rb', line 36 def to_s @tag ||= to_a.compact.join("-") end |
#to_sym ⇒ Object
32 33 34 |
# File 'lib/globalize/locale/language_tag.rb', line 32 def to_sym to_s.to_sym end |