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.
- #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 |
# 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 { |k, _v| k =~ /name(:[a-z]{3})?/ || %w[item parent nomenclature].include?(k) } .each_with_object({}) { |(k, v), h| h[k.to_sym] = v.to_s } @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
22 23 24 25 26 27 28 29 30 |
# File 'lib/onoma/migration/actions/item_creation.rb', line 22 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 |
#options? ⇒ Boolean
18 19 20 |
# File 'lib/onoma/migration/actions/item_creation.rb', line 18 def @options.any? end |