Module: MITS::V3_0::Mapper::PetPolicyMapper

Included in:
MITS::V3_0::Mapper, MITS::V4_1::Mapper
Defined in:
lib/mits/v3.0/mapper/pet_policy_mapper.rb

Instance Method Summary collapse

Instance Method Details

#pet_policies(tags, entity = PetPolicy, secondary_entity = Pet) ⇒ Object



5
6
7
8
# File 'lib/mits/v3.0/mapper/pet_policy_mapper.rb', line 5

def pet_policies(tags, entity = PetPolicy, secondary_entity = Pet)
  tags = [tags] unless tags.is_a? Array
  tags.map { |tag| pet_policy(tag, entity, secondary_entity) }
end

#pet_policy(tag, entity = PetPolicy, secondary_entity = Pet) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/mits/v3.0/mapper/pet_policy_mapper.rb', line 10

def pet_policy(tag, entity = PetPolicy, secondary_entity = Pet)
  if bool(tag[:Allowed])
    entity.new(allowed:      true,
               care:         bool(tag[:PetCare]),
               deposit:      try(tag[:Deposit], :to_f),
               fee:          try(tag[:Fee], :to_f),
               pets:         pets(tag[:Pets], secondary_entity),
               rent:         try(tag[:Rent], :to_f),
               restrictions: tag[:Restrictions])
  else
    entity.new(allowed: false)
  end
end

#pets(tags, entity = Pet) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/mits/v3.0/mapper/pet_policy_mapper.rb', line 24

def pets(tags, entity = Pet)
  tags = [tags] unless tags.is_a? Array
  tags.map do |tag|
    entity.new(count:       tag[:Count].to_i,
               description: tag[:Description],
               size:        tag[:Size],
               weight:      tag[:Weight],
               type:        tag[:PetType])
  end
end