Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address some Code Climate suggestions #163

Merged
merged 1 commit into from Jan 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -20,14 +20,10 @@ def ones
end

def tens_with_ones
if @figures.tens == 2
@translations
.twenties_with_ones(@figures, gender: gender,
is_apocopated: one_apocopated?)
else
super({ gender: gender,
is_apocopated: one_apocopated? })
end
options = { gender: gender, is_apocopated: one_apocopated? }
return @translations.twenties_with_ones(@figures, options) if @figures.tens == 2

super(options)
end

def hundreds
Expand Down
Expand Up @@ -78,7 +78,10 @@ def opaque?
end

def one_thousand?
current_capacity == 1 && figures[0] == 1 && figures.hundreds.nil? && figures.tens.nil?
current_capacity == 1 &&
figures.ones == 1 &&
figures.tens.nil? &&
figures.hundreds.nil?
end

def without_connector?
Expand Down
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require 'numbers_and_words/strategies/figures_converter/options/base'
require 'numbers_and_words/strategies/figures_converter/options/en'
require 'numbers_and_words/strategies/figures_converter/options/en-GB'
require 'numbers_and_words/strategies/figures_converter/options/es'
Expand Down
@@ -0,0 +1,5 @@
# frozen_string_literal: true

require 'numbers_and_words/strategies/figures_converter/options/base/gender'
require 'numbers_and_words/strategies/figures_converter/options/base/ordinal'
require 'numbers_and_words/strategies/figures_converter/options/base/remove_zero'
@@ -0,0 +1,30 @@
# frozen_string_literal: true

module NumbersAndWords
module Strategies
module FiguresConverter
module Options
module Base
class Gender
attr_accessor :strategy, :options

def initialize(proxy, *_args)
@strategy = proxy.strategy
@options = proxy.options
end

def result
active? ? @options[:gender].to_sym : :male
end

private

def active?
@options[:gender]
end
end
end
end
end
end
end
@@ -0,0 +1,28 @@
# frozen_string_literal: true

module NumbersAndWords
module Strategies
module FiguresConverter
module Options
module Base
class Ordinal
def initialize(proxy, *_args)
@strategy = proxy.strategy
@options = proxy.options
end

def result
return :ordinal if active?
end

private

def active?
@options[:ordinal]
end
end
end
end
end
end
end
@@ -0,0 +1,30 @@
# frozen_string_literal: true

module NumbersAndWords
module Strategies
module FiguresConverter
module Options
module Base
class RemoveZero
attr_accessor :strategy, :options

def initialize(proxy, *_args)
@strategy = proxy.strategy
@options = proxy.options
end

def result
active?
end

private

def active?
@options[:remove_zero]
end
end
end
end
end
end
end
Expand Up @@ -5,23 +5,10 @@ module Strategies
module FiguresConverter
module Options
module Cs
class Gender
attr_accessor :strategy, :options

def initialize(proxy, *_args)
@strategy = proxy.strategy
@options = proxy.options
end

class Gender < Base::Gender
def result
active? ? @options[:gender].to_sym : :female
end

private

def active?
@options[:gender]
end
end
end
end
Expand Down
Expand Up @@ -5,21 +5,7 @@ module Strategies
module FiguresConverter
module Options
module Cs
class Ordinal
def initialize(proxy, *_args)
@strategy = proxy.strategy
@options = proxy.options
end

def result
return :ordinal if active?
end

private

def active?
@options[:ordinal]
end
class Ordinal < Base::Ordinal
end
end
end
Expand Down
Expand Up @@ -5,23 +5,7 @@ module Strategies
module FiguresConverter
module Options
module Cs
class RemoveZero
attr_accessor :strategy, :options

def initialize(proxy, *_args)
@strategy = proxy.strategy
@options = proxy.options
end

def result
active?
end

private

def active?
@options[:remove_zero]
end
class RemoveZero < Base::RemoveZero
end
end
end
Expand Down
Expand Up @@ -5,27 +5,18 @@ module Strategies
module FiguresConverter
module Options
module En
class Ordinal
class Ordinal < Base::Ordinal
ZERO_TYPE = :zero
HUNDRED_TYPE = :hundreds
MEGS_TYPE = :megs

def initialize(proxy, *_args)
@strategy = proxy.strategy
@options = proxy.options
end

def result(type)
@type = type
MEGS_TYPE != type ? check_simple_numbers : check_megs_numbers
end

private

def active?
@options[:ordinal]
end

def check_simple_numbers
:ordinal if simple_numbers_condition && active?
end
Expand Down
Expand Up @@ -5,23 +5,7 @@ module Strategies
module FiguresConverter
module Options
module En
class RemoveZero
attr_accessor :strategy, :options

def initialize(proxy, *_args)
@strategy = proxy.strategy
@options = proxy.options
end

def result
active?
end

private

def active?
@options[:remove_zero]
end
class RemoveZero < Base::RemoveZero
end
end
end
Expand Down
Expand Up @@ -5,23 +5,7 @@ module Strategies
module FiguresConverter
module Options
module Es
class Gender
attr_accessor :strategy, :options

def initialize(proxy, *_args)
@strategy = proxy.strategy
@options = proxy.options
end

def result
active? ? @options[:gender].to_sym : :male
end

private

def active?
@options[:gender]
end
class Gender < Base::Gender
end
end
end
Expand Down
Expand Up @@ -5,23 +5,7 @@ module Strategies
module FiguresConverter
module Options
module Es
class RemoveZero
attr_accessor :strategy, :options

def initialize(proxy, *_args)
@strategy = proxy.strategy
@options = proxy.options
end

def result
active?
end

private

def active?
@options[:remove_zero]
end
class RemoveZero < Base::RemoveZero
end
end
end
Expand Down
Expand Up @@ -5,56 +5,7 @@ module Strategies
module FiguresConverter
module Options
module Hu
class Ordinal
ZERO_TYPE = :zero
HUNDRED_TYPE = :hundreds
MEGS_TYPE = :megs

def initialize(proxy, *_args)
@strategy = proxy.strategy
@options = proxy.options
end

def result(type)
@type = type
MEGS_TYPE != type ? check_simple_numbers : check_megs_numbers
end

private

def active?
@options[:ordinal]
end

def check_simple_numbers
:ordinal if simple_numbers_condition && active?
end

def check_megs_numbers
:ordinal if megs_numbers_condition && active?
end

def simple_numbers_condition
current_capacity.nil? &&
(HUNDRED_TYPE != @type ||
HUNDRED_TYPE == @type && simple_number_to_words.empty?)
end

def megs_numbers_condition
current_capacity == language_figures.ordinal_capacity
end

def simple_number_to_words
@strategy.language.simple_number_to_words
end

def current_capacity
@strategy.language.current_capacity
end

def language_figures
@strategy.language.parent_figures
end
class Ordinal < En::Ordinal
end
end
end
Expand Down
Expand Up @@ -5,24 +5,7 @@ module Strategies
module FiguresConverter
module Options
module PtBr
class Gender
attr_accessor :strategy, :options

def initialize(proxy, *_args)
@strategy = proxy.strategy
@options = proxy.options
end

def result
gender = active? ? @options[:gender].to_sym : :male
%i[male female].include?(gender) ? gender : :male
end

private

def active?
@options[:gender]
end
class Gender < Base::Gender
end
end
end
Expand Down