Class: Onoma::Migration::Actions::ItemCreation
- Defined in:
- lib/onoma/migration/actions/item_creation.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#nomenclature ⇒ Object
readonly
Returns the value of attribute nomenclature.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #human_name ⇒ Object
-
#initialize(element) ⇒ ItemCreation
constructor
A new instance of ItemCreation.
- #label ⇒ Object
- #options? ⇒ Boolean
Methods inherited from Base
Constructor Details
#initialize(element) ⇒ ItemCreation
Returns a new instance of ItemCreation.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/onoma/migration/actions/item_creation.rb', line 6 def initialize(element) raise 'Need item attribute' unless element['item'] name = element['item'].split('#') @nomenclature = name.first @name = name.second @options = element.attributes.delete_if do |k, _v| k =~ /name(:[a-z]{3})?/ || %w[item parent nomenclature].include?(k) end.each_with_object({}) do |(k, v), h| h[k.to_sym] = v.to_s end @options[:parent] = element['parent'].to_sym if element.key?('parent') end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/onoma/migration/actions/item_creation.rb', line 5 def name @name end |
#nomenclature ⇒ Object (readonly)
Returns the value of attribute nomenclature.
5 6 7 |
# File 'lib/onoma/migration/actions/item_creation.rb', line 5 def nomenclature @nomenclature end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/onoma/migration/actions/item_creation.rb', line 5 def @options end |
Instance Method Details
#human_name ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/onoma/migration/actions/item_creation.rb', line 27 def human_name updates = [] updates << "#{@name} as name" updates << "#{@parent} as parent" if parent? @options.each do |k, v| updates << "#{v} as #{k}" end sentence = "Create item #{@nomenclature}##{@name} with " + updates.to_sentence end |
#label ⇒ Object
23 24 25 |
# File 'lib/onoma/migration/actions/item_creation.rb', line 23 def label "create_item #{@nomenclature}##{@name}" + (@options.any? ? "(#{@options.simple_print})" : '') end |
#options? ⇒ Boolean
19 20 21 |
# File 'lib/onoma/migration/actions/item_creation.rb', line 19 def @options.any? end |