Class: Onoma::Migration::Actions::ItemCreation

Inherits:
Base
  • Object
show all
Defined in:
lib/onoma/migration/actions/item_creation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

action_name, #action_name

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

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/onoma/migration/actions/item_creation.rb', line 5

def name
  @name
end

#nomenclatureObject (readonly)

Returns the value of attribute nomenclature.



5
6
7
# File 'lib/onoma/migration/actions/item_creation.rb', line 5

def nomenclature
  @nomenclature
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/onoma/migration/actions/item_creation.rb', line 5

def options
  @options
end

Instance Method Details

#human_nameObject



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

Returns:

  • (Boolean)


18
19
20
# File 'lib/onoma/migration/actions/item_creation.rb', line 18

def options?
  @options.any?
end