Class: I18nYamlEditor::Key

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n_yaml_editor/key.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Key

Returns a new instance of Key.



9
10
11
12
# File 'lib/i18n_yaml_editor/key.rb', line 9

def initialize attributes={}
  @name = attributes[:name]
  @translations = Set.new
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/i18n_yaml_editor/key.rb', line 7

def name
  @name
end

#translationsObject

Returns the value of attribute translations.



7
8
9
# File 'lib/i18n_yaml_editor/key.rb', line 7

def translations
  @translations
end

Instance Method Details

#add_translation(translation) ⇒ Object



14
15
16
# File 'lib/i18n_yaml_editor/key.rb', line 14

def add_translation translation
  self.translations.add(translation)
end

#categoryObject



18
19
20
# File 'lib/i18n_yaml_editor/key.rb', line 18

def category
  @category ||= self.name.split(".").first
end

#complete?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/i18n_yaml_editor/key.rb', line 22

def complete?
  self.translations.all? {|t| t.text.to_s !~ /\A\s*\z/} || empty?
end

#empty?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/i18n_yaml_editor/key.rb', line 26

def empty?
  self.translations.all? {|t| t.text.to_s =~ /\A\s*\z/}
end