Class: I18nYamlEditor::Key

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

Overview

This is a key

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Key

Returns a new instance of Key.



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

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

Instance Attribute Details

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#translationsObject

Returns the value of attribute translations.



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

def translations
  @translations
end

Instance Method Details

#add_translation(translation) ⇒ Object

Adds a translation to this key’s list of translations



16
17
18
# File 'lib/i18n_yaml_editor/key.rb', line 16

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

#categoryObject

This key’s category



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

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

#complete?Boolean

Returns:

  • (Boolean)


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

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

#empty?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/i18n_yaml_editor/key.rb', line 29

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