module Kabal
Constants
- VERSION
Public Class Methods
supported_languages()
click to toggle source
# File lib/kabal.rb, line 54 def self.supported_languages languages = Kabal::Config::YamlLoader.yaml_object 'languages' languages.keys end
Public Instance Methods
current_language()
click to toggle source
# File lib/kabal.rb, line 49 def current_language @language ||= 'English' @language end
current_language_supports_fractional?()
click to toggle source
# File lib/kabal.rb, line 64 def current_language_supports_fractional? obj = Object.const_get(language_class_name(current_language)).new obj.supports_fractional? end
current_language_supports_natural?()
click to toggle source
# File lib/kabal.rb, line 59 def current_language_supports_natural? obj = Object.const_get(language_class_name(current_language)).new obj.supports_natural? end
language=(language_to_set)
click to toggle source
# File lib/kabal.rb, line 16 def language=(language_to_set) languages = Kabal::Config::YamlLoader.yaml_object 'languages' if languages[language_to_set] @language = language_to_set else fail NoLanguageSupportError.message end end
language_supports_fractional?(language)
click to toggle source
# File lib/kabal.rb, line 74 def language_supports_fractional?(language) obj = Object.const_get(language_class_name(language)).new obj.supports_fractional? end
language_supports_negative?(language)
click to toggle source
# File lib/kabal.rb, line 69 def language_supports_negative?(language) obj = Object.const_get(language_class_name(language)).new obj.supports_negative? end
maximum_for(language)
click to toggle source
# File lib/kabal.rb, line 79 def maximum_for(language) obj = Object.const_get(language_class_name(language)).new obj.max_value end
minimum_for(language)
click to toggle source
# File lib/kabal.rb, line 84 def minimum_for(language) obj = Object.const_get(language_class_name(language)).new obj.min_value end
to_text(number)
click to toggle source
# File lib/kabal.rb, line 12 def to_text(number) to_text_in_language number, current_language end
to_text_in_language(number, language_at_once)
click to toggle source
# File lib/kabal.rb, line 25 def to_text_in_language(number, language_at_once) number = string_convert number languages = Kabal::Config::YamlLoader.yaml_object 'languages' if languages[language_at_once] convert_in_language number, language_at_once elsif languages.values.include? language_at_once.to_s need_language = languages.keys.select { |key| languages[key] == language_at_once.to_s }.first convert_in_language number, need_language else NoLanguageSupportError.message end end
to_text_in_language_by_index(number, language_at_once_index)
click to toggle source
# File lib/kabal.rb, line 38 def to_text_in_language_by_index(number, language_at_once_index) number = string_convert number languages = Kabal::Config::YamlLoader.yaml_object('languages').to_a if languages[language_at_once_index] obj = Object.const_get(language_class_name(languages[language_at_once_index].first)).new obj.convert number else NoLanguageSupportError.message end end
Private Instance Methods
convert_in_language(number, language)
click to toggle source
# File lib/kabal.rb, line 118 def convert_in_language(number, language) if number > maximum_for(language) || number < minimum_for(language) NumberOutRangeError.message else obj = Object.const_get(language_class_name(language)).new obj.convert number end end
language_class_name(language)
click to toggle source
# File lib/kabal.rb, line 114 def language_class_name(language) 'Kabal::' + language.to_s end
string_convert(number)
click to toggle source
# File lib/kabal.rb, line 98 def string_convert(number) if number.is_a? String if string_is_float? number Kernel::Float(number) else number.to_i end else number end end
string_is_float?(number)
click to toggle source
# File lib/kabal.rb, line 110 def string_is_float?(number) number.include? '.' end