Module: NfeReader::CreatorHelper

Included in:
Billing, Cane, Header, Information, Nfe, Product, Transport
Defined in:
lib/nfe_reader/helpers/creator_helper.rb

Instance Method Summary collapse

Instance Method Details

#create_resource(klass, attrs = {}) ⇒ Object

[View source]

3
4
5
6
# File 'lib/nfe_reader/helpers/creator_helper.rb', line 3

def create_resource(klass, attrs = {})
  return unless attrs
  klass.new(attrs)
end

#create_resources(klass, attrs = {}) ⇒ Object

[View source]

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/nfe_reader/helpers/creator_helper.rb', line 8

def create_resources(klass, attrs = {})
  resources = []

  return resources unless attrs

  if attrs.is_a? Hash
    resources << klass.new(attrs)
  else
    attrs.each do |a|
      resources << klass.new(a)
    end
  end

  resources
end

#to_array(attrs = {}) ⇒ Object

[View source]

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/nfe_reader/helpers/creator_helper.rb', line 24

def to_array(attrs = {})
  array = []

  return [] unless attrs

  if attrs.is_a? Array
    attrs.each do |hash|
      array << hash.map { |key, value| value }
    end
  else
    array << attrs.map { |key, value| value }
  end

  array
end