Class: PecCalcClient::Calc

Inherits:
Object
  • Object
show all
Extended by:
RequestClass
Includes:
RequestObject
Defined in:
lib/pec_calc_client/calc.rb

Constant Summary collapse

URL =
'http://pecom.ru/bitrix/components/pecom/calc/ajax.php'
PARAMS =
%w( plombir strah ashan night pal pallets )

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RequestClass

set_readers

Methods included from RequestObject

#init_params, #to_h

Constructor Details

#initialize(params) ⇒ Calc

Returns a new instance of Calc.



14
15
16
# File 'lib/pec_calc_client/calc.rb', line 14

def initialize(params)
  init_params params
end

Instance Attribute Details

#deliveryObject

Returns the value of attribute delivery.



12
13
14
# File 'lib/pec_calc_client/calc.rb', line 12

def delivery
  @delivery
end

#placesObject

Returns the value of attribute places.



12
13
14
# File 'lib/pec_calc_client/calc.rb', line 12

def places
  @places
end

#takeObject

Returns the value of attribute take.



12
13
14
# File 'lib/pec_calc_client/calc.rb', line 12

def take
  @take
end

Instance Method Details

#calcObject



18
19
20
21
# File 'lib/pec_calc_client/calc.rb', line 18

def calc
  result = Connector.new(URL).request(prepare_params)
  prepare_result result.to_hash
end

#prepare_paramsObject



23
24
25
26
27
28
29
# File 'lib/pec_calc_client/calc.rb', line 23

def prepare_params
  out = to_h
  out[:deliver] = @delivery.to_h
  out[:take] = @take.to_h
  out[:places] = @places.each_with_index.map { |place, i| [i, place.to_a] }.to_h
  out
end