Skip to content

Commit

Permalink
Remove ActiveSupport dependency
Browse files Browse the repository at this point in the history
This commit removes the dependency on the `ActiveSupport` gem by doing
the following:

- Replace `constantize` with `Object.const_get()`
- Remove the following `Object` methods:
    - `blank?`
    - `present?`
- Remove the following `String` methods:
    - `camelcase`
    - `titleize`
    - `underscore`

Closes kslazarev#106
  • Loading branch information
jlduran committed Jun 20, 2017
1 parent 4235411 commit 3239583
Show file tree
Hide file tree
Showing 39 changed files with 51 additions and 50 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## 0.10.7 (Next)
## 0.11.0 (Next)

### Features
* Your contribution here.
* Remove dependency on `ActiveSupport` gem. \[[#140](https://github.com/kslazarev/numbers_and_words/pull/140)\]

## 0.10.6 (June 11, 2017)

Expand Down
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
source 'https://rubygems.org'

gem 'activesupport'
gem 'i18n'

group :development do
Expand Down
3 changes: 0 additions & 3 deletions lib/numbers_and_words.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
require 'rubygems'
require 'i18n'
require 'i18n/backend/pluralization'
require 'active_support/inflector'
require 'active_support/core_ext/object'

require 'numbers_and_words/translations'
require 'numbers_and_words/strategies'
Expand Down
2 changes: 1 addition & 1 deletion lib/numbers_and_words/i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def local_language locale = ::I18n.locale
end

def language_class_name
::I18n.locale.to_s.titleize.gsub ' ', ''
::I18n.locale.to_s.split('-').collect(&:capitalize).join
end

def locale_files
Expand Down
2 changes: 1 addition & 1 deletion lib/numbers_and_words/i18n/pluralization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'numbers_and_words/i18n/plurals/fr'
require 'numbers_and_words/i18n/plurals/lv'
require 'numbers_and_words/i18n/plurals/lt'
require 'numbers_and_words/i18n/plurals/pt_br'
require 'numbers_and_words/i18n/plurals/pt-BR'

module NumbersAndWords
module I18n
Expand Down
14 changes: 9 additions & 5 deletions lib/numbers_and_words/i18n/plurals/plurals.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
Hash[
NumbersAndWords::I18n::Pluralization.languages.map { |language|
[language.to_sym, {:i18n => {:plural => {
:rule => "NumbersAndWords::I18n::Plurals::#{language.titleize.gsub(/ /, '')}::RULE".constantize
}}}]
}
NumbersAndWords::I18n::Pluralization.languages.map do |language|
[language.to_sym, {
i18n: {
plural: {
rule: Object.const_get("NumbersAndWords::I18n::Plurals::#{language.split('-').collect(&:capitalize).join}::RULE")
}
}
}]
end
]
File renamed without changes.
6 changes: 3 additions & 3 deletions lib/numbers_and_words/strategies/array_joiner/languages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
require 'numbers_and_words/strategies/array_joiner/languages/base'

require 'numbers_and_words/strategies/array_joiner/languages/en'
require 'numbers_and_words/strategies/array_joiner/languages/en_gb'
require 'numbers_and_words/strategies/array_joiner/languages/en-GB'
require 'numbers_and_words/strategies/array_joiner/languages/hu'
require 'numbers_and_words/strategies/array_joiner/languages/ru'
require 'numbers_and_words/strategies/array_joiner/languages/ua'
require 'numbers_and_words/strategies/array_joiner/languages/pt_br'
require 'numbers_and_words/strategies/array_joiner/languages/pt-BR'

module NumbersAndWords
module Strategies
module ArrayJoiner
module Languages
class << self
def factory strategy
"#{name}::#{I18n.language_class_name}".constantize.new strategy
Object.const_get("#{name}::#{I18n.language_class_name}").new strategy
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def elements_logic
end

def union_element
@elements.first.blank? ? "#{union_separator} " : super
@elements.first.empty? ? "#{union_separator} " : super
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ module Families
module Base

def elements_logic
@elements.first.blank? ? @elements.last : @elements.join(union_element)
@elements.first.empty? ? @elements.last : @elements.join(union_element)
end

def union_element
union_separator.present? ? " #{union_separator} " : ' '
union_separator.empty? ? ' ' : " #{union_separator} "
end

def union_separator
Expand All @@ -21,4 +21,4 @@ def union_separator
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'numbers_and_words/strategies/figures_converter/decorators/base'
require 'numbers_and_words/strategies/figures_converter/decorators/en'
require 'numbers_and_words/strategies/figures_converter/decorators/en_gb'
require 'numbers_and_words/strategies/figures_converter/decorators/en-GB'
require 'numbers_and_words/strategies/figures_converter/decorators/ru'
require 'numbers_and_words/strategies/figures_converter/decorators/pt_br'
require 'numbers_and_words/strategies/figures_converter/decorators/pt-BR'
require 'numbers_and_words/strategies/figures_converter/decorators/hu'
require 'numbers_and_words/strategies/figures_converter/decorators/ua'

Expand All @@ -24,11 +24,11 @@ def enabled_decorator options
end

def decorator_class method_name
method_name ? decorator_class_name(method_name).constantize : Decorators::Base
method_name ? Object.const_get(decorator_class_name(method_name)) : Decorators::Base
end

def decorator_class_name method_name
"#{name}::#{I18n.language_class_name}::#{method_name.to_s.camelcase}"
"#{name}::#{I18n.language_class_name}::#{method_name.to_s.split('_').collect(&:capitalize).join}"
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require 'numbers_and_words/strategies/figures_converter/decorators/en_gb/base'
require 'numbers_and_words/strategies/figures_converter/decorators/en_gb/fractional'
require 'numbers_and_words/strategies/figures_converter/decorators/en_gb/integral'
require 'numbers_and_words/strategies/figures_converter/decorators/en-GB/base'
require 'numbers_and_words/strategies/figures_converter/decorators/en-GB/fractional'
require 'numbers_and_words/strategies/figures_converter/decorators/en-GB/integral'
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require 'numbers_and_words/strategies/figures_converter/decorators/pt_br/base'
require 'numbers_and_words/strategies/figures_converter/decorators/pt_br/integral'
require 'numbers_and_words/strategies/figures_converter/decorators/pt_br/fractional'
require 'numbers_and_words/strategies/figures_converter/decorators/pt-BR/base'
require 'numbers_and_words/strategies/figures_converter/decorators/pt-BR/fractional'
require 'numbers_and_words/strategies/figures_converter/decorators/pt-BR/integral'
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
require 'numbers_and_words/strategies/figures_converter/languages/families/latin'

require 'numbers_and_words/strategies/figures_converter/languages/en'
require 'numbers_and_words/strategies/figures_converter/languages/en_gb'
require 'numbers_and_words/strategies/figures_converter/languages/en-GB'
require 'numbers_and_words/strategies/figures_converter/languages/fr'
require 'numbers_and_words/strategies/figures_converter/languages/hu'
require 'numbers_and_words/strategies/figures_converter/languages/et'
Expand All @@ -24,7 +24,7 @@
require 'numbers_and_words/strategies/figures_converter/languages/ru'
require 'numbers_and_words/strategies/figures_converter/languages/ua'
require 'numbers_and_words/strategies/figures_converter/languages/pt'
require 'numbers_and_words/strategies/figures_converter/languages/pt_br'
require 'numbers_and_words/strategies/figures_converter/languages/pt-BR'

require 'numbers_and_words/strategies/figures_converter/languages/ka'

Expand All @@ -34,7 +34,7 @@ module FiguresConverter
module Languages
class << self
def factory strategy
"#{name}::#{I18n.language_class_name}".constantize.new strategy
Object.const_get("#{name}::#{I18n.language_class_name}").new strategy
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def print_words
end

def print_megs_words
[print_megs, print_other].select(&:present?).join ' '
[print_megs, print_other].reject(&:empty?).join ' '
end

def complex_number_to_words
Expand Down Expand Up @@ -41,7 +41,7 @@ def megs
def print_megs
complex_part[1..-1].map { |el|
[el[1..-1].to_a.reverse.join(''), el.first].join(' ')
}.select(&:present?).reverse.join(' ')
}.reject(&:empty?).reverse.join(' ')
end

def print_other
Expand Down
8 changes: 4 additions & 4 deletions lib/numbers_and_words/strategies/figures_converter/options.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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/en-GB'
require 'numbers_and_words/strategies/figures_converter/options/ru'
require 'numbers_and_words/strategies/figures_converter/options/pt_br'
require 'numbers_and_words/strategies/figures_converter/options/pt-BR'
require 'numbers_and_words/strategies/figures_converter/options/ua'
require 'numbers_and_words/strategies/figures_converter/options/hu'

Expand All @@ -18,15 +18,15 @@ def initialize strategy, options
end

def method_missing method_name, *args, &block
proxy_class_name(method_name).constantize.new self, args, block
Object.const_get(proxy_class_name(method_name)).new self, args, block
rescue NameError
return nil
end

private

def proxy_class_name method_name
"#{module_name}::#{I18n.language_class_name}::#{method_name.to_s.camelcase}"
"#{module_name}::#{I18n.language_class_name}::#{method_name.to_s.split('_').collect(&:capitalize).join}"
end

def module_name
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'numbers_and_words/strategies/figures_converter/options/en_gb/hundreds_with_union'
require 'numbers_and_words/strategies/figures_converter/options/en_gb/remove_hyphen'
require 'numbers_and_words/strategies/figures_converter/options/en_gb/ordinal'
require 'numbers_and_words/strategies/figures_converter/options/en_gb/pronounced'
require 'numbers_and_words/strategies/figures_converter/options/en_gb/remove_zero'
require 'numbers_and_words/strategies/figures_converter/options/en-GB/hundreds_with_union'
require 'numbers_and_words/strategies/figures_converter/options/en-GB/remove_hyphen'
require 'numbers_and_words/strategies/figures_converter/options/en-GB/ordinal'
require 'numbers_and_words/strategies/figures_converter/options/en-GB/pronounced'
require 'numbers_and_words/strategies/figures_converter/options/en-GB/remove_zero'
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require 'numbers_and_words/strategies/figures_converter/options/pt_br/gender'
require 'numbers_and_words/strategies/figures_converter/options/pt_br/ordinal'
require 'numbers_and_words/strategies/figures_converter/options/pt_br/remove_zero'
require 'numbers_and_words/strategies/figures_converter/options/pt-BR/gender'
require 'numbers_and_words/strategies/figures_converter/options/pt-BR/ordinal'
require 'numbers_and_words/strategies/figures_converter/options/pt-BR/remove_zero'
6 changes: 3 additions & 3 deletions lib/numbers_and_words/translations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require 'numbers_and_words/translations/extensions/fraction_significance'
require 'numbers_and_words/translations/ru'
require 'numbers_and_words/translations/en'
require 'numbers_and_words/translations/en_gb'
require 'numbers_and_words/translations/en-GB'
require 'numbers_and_words/translations/ua'
require 'numbers_and_words/translations/tr'
require 'numbers_and_words/translations/fr'
Expand All @@ -19,14 +19,14 @@
require 'numbers_and_words/translations/lt'
require 'numbers_and_words/translations/de'
require 'numbers_and_words/translations/pt'
require 'numbers_and_words/translations/pt_br'
require 'numbers_and_words/translations/pt-BR'
require 'numbers_and_words/translations/ka'

module NumbersAndWords
module Translations
class << self
def factory
"#{name}::#{I18n.language_class_name}".constantize.new
Object.const_get("#{name}::#{I18n.language_class_name}").new
end
end
end
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion spec/support/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ def fixture_examples type, language
dir_name = File.dirname($1)
fixture_file = "#{language}.yml"
YAML::load File.open(
[dir_name, type.inspect.underscore, 'fixture_examples', fixture_file].join('/')
[dir_name, type.inspect, 'fixture_examples', fixture_file].join('/')
)
end

0 comments on commit 3239583

Please sign in to comment.