Class: BuhoCfdi::ParamsBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/buho_cfdi/params_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ ParamsBuilder

Returns a new instance of ParamsBuilder.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/buho_cfdi/params_builder.rb', line 9

def initialize(params)
  @params = params

  build_receipt
  build_cfdi_related
  build_issuer
  build_receiver
  build_concepts
  build_taxes

  receipt
end

Instance Attribute Details

#paramsObject

Returns the value of attribute params.



4
5
6
# File 'lib/buho_cfdi/params_builder.rb', line 4

def params
  @params
end

#receiptObject

Returns the value of attribute receipt.



4
5
6
# File 'lib/buho_cfdi/params_builder.rb', line 4

def receipt
  @receipt
end

Instance Method Details



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/buho_cfdi/params_builder.rb', line 30

def build_cfdi_related
  if params.fetch(:receipt).include?(:cfdi_related_attributes)
    @receipt.build_child! ::Nodes::CfdiRelated, params.fetch(:receipt).fetch(:cfdi_related_attributes)

    if params.fetch(:receipt).fetch(:cfdi_related_attributes).include?(:related_attributes)
      @receipt.nodes_cfdirelated.build_children ::Nodes::Related

      params.fetch(:receipt).fetch(:cfdi_related_attributes).fetch(:related_attributes).each do |params|
        @receipt.nodes_cfdirelated.nodes_related.add params
      end
    end
  else
    nil
  end
end

#build_conceptsObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/buho_cfdi/params_builder.rb', line 62

def build_concepts
  if params.include?(:receipt) && params.fetch(:receipt).include?(:concepts_attributes)
    @receipt.build_children ::Nodes::Concept

    params.fetch(:receipt).fetch(:concepts_attributes).each do |params|

      concept = @receipt.nodes_concept.add params

      if params.include?(:transferred_attributes)
        concept.build_children ::Nodes::TaxTransferred

        params.fetch(:transferred_attributes).each do |params|
          concept.nodes_taxtransferred.add params
        end
      end

      if params.include?(:detained_attributes)
        concept.build_children ::Nodes::TaxDetained

        params.fetch(:detained_attributes).each do |params|
          concept.nodes_taxdetained.add params
        end
      end

      if params.include?(:customs_information_attributes)
        concept.build_child! ::Nodes::CustomsInformation, params.fetch(:customs_information_attributes)
      end

      if params.include?(:property_account_attributes)
        concept.build_child! ::Nodes::PropertyAccount, params.fetch(:property_account_attributes)
      end

      if params.include?(:part_attributes)
        concept.build_child! ::Nodes::Part, params.fetch(:part_attributes)
      end
    end
  else
    nil
  end
end

#build_issuerObject



46
47
48
49
50
51
52
# File 'lib/buho_cfdi/params_builder.rb', line 46

def build_issuer
  if params.include?(:receipt) && params.fetch(:receipt).include?(:issuer_attributes)
    @receipt.build_child! ::Nodes::Issuer, params.fetch(:receipt).fetch(:issuer_attributes)
  else
    nil
  end
end

#build_receiptObject



22
23
24
25
26
27
28
# File 'lib/buho_cfdi/params_builder.rb', line 22

def build_receipt
  if params.include?(:receipt)
    @receipt = ::Nodes::Receipt.new params.fetch(:receipt)
  else
    nil
  end
end

#build_receiverObject



54
55
56
57
58
59
60
# File 'lib/buho_cfdi/params_builder.rb', line 54

def build_receiver
  if params.include?(:receipt) && params.fetch(:receipt).include?(:receiver_attributes)
    @receipt.build_child! ::Nodes::Receiver, params.fetch(:receipt).fetch(:receiver_attributes)
  else
    nil
  end
end

#build_taxesObject



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/buho_cfdi/params_builder.rb', line 103

def build_taxes
  if params.include?(:receipt) && params.fetch(:receipt).include?(:taxes_attributes)
    @receipt.build_child! ::Nodes::Taxes, params.fetch(:receipt).fetch(:taxes_attributes)

    if params.fetch(:receipt).fetch(:taxes_attributes).include?(:transferred_attributes)
      @receipt.nodes_taxes.build_children ::Nodes::Transferred

      params.fetch(:receipt).fetch(:taxes_attributes).fetch(:transferred_attributes).each do |params|
        @receipt.nodes_taxes.nodes_transferred.add params
      end
    end

    if params.fetch(:receipt).fetch(:taxes_attributes).include?(:detained_attributes)
      @receipt.nodes_taxes.build_children ::Nodes::Detained

      params.fetch(:receipt).fetch(:taxes_attributes).fetch(:detained_attributes).each do |params|
        @receipt.nodes_taxes.nodes_detained.add params
      end
    end
  end
end