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
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

#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



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

#labelObject



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

Returns:

  • (Boolean)


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

def options?
  @options.any?
end