Skip to content

Commit

Permalink
Merge pull request #480 from roomorama/release/0.12.13
Browse files Browse the repository at this point in the history
Release/0.12.13
  • Loading branch information
keang authored Oct 24, 2016
2 parents 247afef + c913840 commit 89dba86
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 27 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ This file summarises the most important changes that went live on each release
of Concierge. Please check the Wiki entry on the release process to understand
how this file is formatted and how the process works.

## [0.12.13] - 2016-10-24
### Added
- Rentals United: add translations for zh de es languages for late/early fees

## [0.12.12] - 2016-10-21
### Added
- Rentals United: add late check-in / early check-out fees to description_append
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,19 @@ module Converters
#
# This class converts property's check-in and check-out fee rules to text.
class CheckInOutFees
LATE_ARRIVAL_FEES_TITLE = "* Late arrival fees:"
EARLY_DEPARTURE_FEES_TITLE = "* Early departure fees:"
SUPPORTED_LOCALES = %i(en zh de es)
LATE_ARRIVAL_FEES_TITLE = {
en: "* Late arrival fees:",
zh: "* 晚到费用:",
de: "* Gebühren für späte Ankunft:",
es: "* Penalización por retraso en la llegada:"
}
EARLY_DEPARTURE_FEES_TITLE = {
en: "* Early departure fees:",
zh: "* 提早离店费用:",
de: "* Gebühren für frühe Abreise:",
es: "* La comisión a aplicar por salida anticipada:"
}

# Initialize +RentalsUnited::Converters::CheckInOutFees+
#
Expand All @@ -19,7 +30,17 @@ def initialize(ru_property, currency)
@currency = currency
end

# Output format:
# Output hash format:
#
# {
# en: "en tranlation",
# de: "de tranlation",
# zh: "zh tranlation",
# es: "es tranlation"
# }
#
# Translation for every lang is presented as string in the next format:
#
# * Late arrival fees:\n
# - 20:00 - 00:00 : $10\n
# - 00:00 - 05:00 : $20\n
Expand All @@ -28,36 +49,44 @@ def initialize(ru_property, currency)
# - 13:00 - 15:00 : $10\n
# - 11:00 - 13:00 : $20\n
# - ..
def as_text
#
# If there is no any fees, method returns `nil`
def build_tranlations
return nil if empty_fees?

[
formatted_late_arrival_fees,
formatted_early_departure_fees
].compact.join("\n")
hash = {}
SUPPORTED_LOCALES.each { |locale| hash[locale] = localize_fees(locale) }
hash
end

private
attr_reader :late_arrival_fees, :early_departure_fees, :currency

def localize_fees(lang)
[
formatted_late_arrival_fees(lang),
formatted_early_departure_fees(lang)
].compact.join("\n")
end

def empty_fees?
(late_arrival_fees + early_departure_fees).empty?
end

def formatted_late_arrival_fees
def formatted_late_arrival_fees(lang)
return nil unless late_arrival_fees.any?

[
LATE_ARRIVAL_FEES_TITLE,
LATE_ARRIVAL_FEES_TITLE[lang],
formatted_rules(late_arrival_fees)
].join("\n")
end

def formatted_early_departure_fees
def formatted_early_departure_fees(lang)
return nil unless early_departure_fees.any?

[
EARLY_DEPARTURE_FEES_TITLE,
EARLY_DEPARTURE_FEES_TITLE[lang],
formatted_rules(early_departure_fees)
].join("\n")
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def build_roomorama_property
property.number_of_single_beds = ru_property.number_of_single_beds
property.number_of_double_beds = ru_property.number_of_double_beds
property.number_of_sofa_beds = ru_property.number_of_sofa_beds
property.description_append = description_append
property.country_code = country_code(location)
property.currency = location.currency
property.city = location.city
Expand All @@ -91,6 +90,7 @@ def build_roomorama_property
set_security_deposit!(property)
set_rates!(property)
set_cleaning!(property)
set_description_append!(property)

Result.new(property)
end
Expand Down Expand Up @@ -149,8 +149,16 @@ def country_code(location)
Converters::CountryCode.code_by_name(location.country)
end

def description_append
Converters::CheckInOutFees.new(ru_property, location.currency).as_text
def set_description_append!(property)
converter = Converters::CheckInOutFees.new(ru_property, location.currency)
tranlations = converter.build_tranlations

if tranlations
property.description_append = tranlations.fetch(:en)
property.zh.description_append = tranlations.fetch(:zh)
property.de.description_append = tranlations.fetch(:de)
property.es.description_append = tranlations.fetch(:es)
end
end

def supported_property_type?
Expand Down
2 changes: 1 addition & 1 deletion lib/concierge/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Concierge
VERSION = "0.12.12"
VERSION = "0.12.13"
end
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,28 @@ module RentalsUnited
let(:currency) { "EUR" }
let(:subject) { described_class.new(ru_property, currency) }

it "converts fee rules to text" do
expect(subject.as_text).to eq(
"* Late arrival fees:\n- 14:00 - 15:00 : 20.0 EUR\n- 13:00 - 14:00 : 10.0 EUR\n* Early departure fees:\n- 17:00 - 18:00 : 67.0 EUR\n- 14:00 - 15:00 : 45.0 EUR"
it "converts fee rules to hash" do
expect(subject.build_tranlations).to eq(
{
en: "* Late arrival fees:\n- 14:00 - 15:00 : 20.0 EUR\n- 13:00 - 14:00 : 10.0 EUR\n* Early departure fees:\n- 17:00 - 18:00 : 67.0 EUR\n- 14:00 - 15:00 : 45.0 EUR",
zh: "* 晚到费用:\n- 14:00 - 15:00 : 20.0 EUR\n- 13:00 - 14:00 : 10.0 EUR\n* 提早离店费用:\n- 17:00 - 18:00 : 67.0 EUR\n- 14:00 - 15:00 : 45.0 EUR",
de: "* Gebühren für späte Ankunft:\n- 14:00 - 15:00 : 20.0 EUR\n- 13:00 - 14:00 : 10.0 EUR\n* Gebühren für frühe Abreise:\n- 17:00 - 18:00 : 67.0 EUR\n- 14:00 - 15:00 : 45.0 EUR",
es: "* Penalización por retraso en la llegada:\n- 14:00 - 15:00 : 20.0 EUR\n- 13:00 - 14:00 : 10.0 EUR\n* La comisión a aplicar por salida anticipada:\n- 17:00 - 18:00 : 67.0 EUR\n- 14:00 - 15:00 : 45.0 EUR"
}
)
end

context "when there is only late fees" do
let(:early_departure_fees) { [] }

it "converts fee rules to text when there is no late fees" do
expect(subject.as_text).to eq(
"* Late arrival fees:\n- 14:00 - 15:00 : 20.0 EUR\n- 13:00 - 14:00 : 10.0 EUR"
expect(subject.build_tranlations).to eq(
{
en: "* Late arrival fees:\n- 14:00 - 15:00 : 20.0 EUR\n- 13:00 - 14:00 : 10.0 EUR",
zh: "* 晚到费用:\n- 14:00 - 15:00 : 20.0 EUR\n- 13:00 - 14:00 : 10.0 EUR",
de: "* Gebühren für späte Ankunft:\n- 14:00 - 15:00 : 20.0 EUR\n- 13:00 - 14:00 : 10.0 EUR",
es: "* Penalización por retraso en la llegada:\n- 14:00 - 15:00 : 20.0 EUR\n- 13:00 - 14:00 : 10.0 EUR"
}
)
end
end
Expand All @@ -73,8 +83,13 @@ module RentalsUnited
let(:late_arrival_fees) { [] }

it "converts fee rules to text when there is no late fees" do
expect(subject.as_text).to eq(
"* Early departure fees:\n- 17:00 - 18:00 : 67.0 EUR\n- 14:00 - 15:00 : 45.0 EUR"
expect(subject.build_tranlations).to eq(
{
en: "* Early departure fees:\n- 17:00 - 18:00 : 67.0 EUR\n- 14:00 - 15:00 : 45.0 EUR",
zh: "* 提早离店费用:\n- 17:00 - 18:00 : 67.0 EUR\n- 14:00 - 15:00 : 45.0 EUR",
de: "* Gebühren für frühe Abreise:\n- 17:00 - 18:00 : 67.0 EUR\n- 14:00 - 15:00 : 45.0 EUR",
es: "* La comisión a aplicar por salida anticipada:\n- 17:00 - 18:00 : 67.0 EUR\n- 14:00 - 15:00 : 45.0 EUR"
}
)
end
end
Expand All @@ -84,7 +99,7 @@ module RentalsUnited
let(:early_departure_fees) { [] }

it "returns nil" do
expect(subject.as_text).to be_nil
expect(subject.build_tranlations).to be_nil
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,39 @@
end

context "when mapping late/early fees" do
let(:translations) {
{
en: "test 1",
de: "test 2",
zh: "test 3",
es: "test 4"
}
}

it "sets fees to the description_append field" do
expect_any_instance_of(RentalsUnited::Converters::CheckInOutFees)
.to(receive(:as_text))
.and_return("Check in rules")
.to(receive(:build_tranlations))
.and_return(translations)

expect(property.description_append).to eq("test 1")
expect(property.de.description_append).to eq("test 2")
expect(property.zh.description_append).to eq("test 3")
expect(property.es.description_append).to eq("test 4")
end

expect(property.description_append).to eq("Check in rules")
context "when tranlations are empty" do
let(:translations) { nil }

it "sets fees to the description_append field" do
expect_any_instance_of(RentalsUnited::Converters::CheckInOutFees)
.to(receive(:build_tranlations))
.and_return(translations)

expect(property.description_append).to be_nil
expect(property.de.description_append).to be_nil
expect(property.zh.description_append).to be_nil
expect(property.es.description_append).to be_nil
end
end
end
end

0 comments on commit 89dba86

Please sign in to comment.