Class: I27r::Line
- Inherits:
-
Object
- Object
- I27r::Line
- Defined in:
- lib/generators/i18n/translation/lib/yaml.rb
Instance Attribute Summary collapse
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
- #generated? ⇒ Boolean
- #indent ⇒ Object
-
#initialize(text, options = {}) ⇒ Line
constructor
A new instance of Line.
- #key ⇒ Object
- #to_s ⇒ Object
- #value ⇒ Object
- #value=(val) ⇒ Object
- #yaml? ⇒ Boolean
Constructor Details
#initialize(text, options = {}) ⇒ Line
Returns a new instance of Line.
12 13 14 15 16 |
# File 'lib/generators/i18n/translation/lib/yaml.rb', line 12 def initialize(text, = {}) @generated = !![:generated] || text.ends_with?(' #g') @yaml = YAML.load text.to_s + ' ' @text = text end |
Instance Attribute Details
#text ⇒ Object (readonly)
Returns the value of attribute text.
9 10 11 |
# File 'lib/generators/i18n/translation/lib/yaml.rb', line 9 def text @text end |
Instance Method Details
#generated? ⇒ Boolean
30 31 32 |
# File 'lib/generators/i18n/translation/lib/yaml.rb', line 30 def generated? @generated end |
#indent ⇒ Object
26 27 28 |
# File 'lib/generators/i18n/translation/lib/yaml.rb', line 26 def indent yaml? ? @text.scan(/^ */).first : '' end |
#key ⇒ Object
18 19 20 |
# File 'lib/generators/i18n/translation/lib/yaml.rb', line 18 def key yaml? ? @yaml.keys.first : nil end |
#to_s ⇒ Object
45 46 47 |
# File 'lib/generators/i18n/translation/lib/yaml.rb', line 45 def to_s "#{@text}#{' #g' if generated? && yaml? && !value.nil? && !@text.ends_with?(' #g')}" end |
#value ⇒ Object
22 23 24 |
# File 'lib/generators/i18n/translation/lib/yaml.rb', line 22 def value yaml? ? @yaml.values.first : nil end |
#value=(val) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/generators/i18n/translation/lib/yaml.rb', line 38 def value=(val) if @yaml[self.key] != val @yaml[self.key] = val generate_text self.indent end end |
#yaml? ⇒ Boolean
34 35 36 |
# File 'lib/generators/i18n/translation/lib/yaml.rb', line 34 def yaml? @yaml.is_a?(Hash) && @yaml.keys.first.is_a?(String) end |