Class: Lazier::Settings
Overview
Settings for the extensions.
Instance Attribute Summary (collapse)
-
- (Hash) boolean_names
readonly
String representations of booleans.
-
- (Hash) date_formats
readonly
Custom date and time formats.
-
- (Hash) date_names
readonly
String representations of days and months.
-
- (Hash) format_number
readonly
Settings for numbers formatting.
-
- (R18n::Translation) i18n
The translation object.
Class Method Summary (collapse)
-
+ (Settings) instance(force = false)
Returns the singleton instance of the settings.
Instance Method Summary (collapse)
-
- (Settings) initialize
constructor
Initializes a new settings object.
-
- (Object) setup
Setups the current instance.
-
- (Hash) setup_boolean_names(true_name = nil, false_name = nil)
Setups strings representation of booleans.
-
- (Hash) setup_date_formats(formats = nil, replace = false)
Setups custom formats for dates and times.
-
- (Hash) setup_date_names(long_months = nil, short_months = nil, long_days = nil, short_days = nil)
Setups strings representation of days and months.
-
- (Hash) setup_format_number(prec = 2, decimal_separator = ".", add_string = "", k_separator = ",")
Setups formatters for a number.
Methods included from I18n
Constructor Details
- (Settings) initialize
Initializes a new settings object.
38 39 40 41 |
# File 'lib/lazier/settings.rb', line 38 def initialize self.i18n_setup(:lazier, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/")) self.setup end |
Instance Attribute Details
- (Hash) boolean_names (readonly)
String representations of booleans.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/lazier/settings.rb', line 20 class Settings attr_reader :format_number attr_reader :boolean_names attr_reader :date_names attr_reader :date_formats include Lazier::I18n # Returns the singleton instance of the settings. # # @param force [Boolean] If to force recreation of the instance. # @return [Settings] The singleton instance of the settings. def self.instance(force = false) @instance = nil if force @instance ||= self.new end # Initializes a new settings object. def initialize self.i18n_setup(:lazier, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/")) self.setup end # Setups the current instance. def setup self.setup_format_number self.setup_boolean_names self.setup_date_formats self.setup_date_names end # Set the current locale for messages. # # @param locale [String] The new locale. Default is the current system locale. # @return [R18n::Translation] The new translation object. def i18n=(locale) super(locale) self.setup end # Setups formatters for a number. # @see Object#format_number # # @param prec [Fixnum] The precision to show. # @param decimal_separator [String] The string to use as decimal separator. # @param add_string [String] The string to append to the number. # @param k_separator [String] The string to use as thousands separator. # @return [Hash] The new formatters. def setup_format_number(prec = 2, decimal_separator = ".", add_string = "", k_separator = ",") @format_number = { prec: prec, decimal_separator: decimal_separator, add_string: add_string, k_separator: k_separator} end # Setups strings representation of booleans. # @see Object#format_boolean # # @param true_name [String] The string representation of `true`. Defaults to `Yes`. # @param false_name [String] The string representation of `false`. Defaults to `No`. # @return [Hash] The new representations. def setup_boolean_names(true_name = nil, false_name = nil) true_name ||= self.i18n.boolean[0] false_name ||= self.i18n.boolean[1] @boolean_names = {true => true_name, false => false_name} end # Setups custom formats for dates and times. # @see DateTime#lstrftime # # @param formats [Hash] The format to add or replace. # @param replace [Boolean] If to discard current formats. # @return [Hash] The new formats. def setup_date_formats(formats = nil, replace = false) formats = {ct_date: "%Y-%m-%d", ct_time: "%H:%M:%S", ct_date_time: "%F %T", ct_iso_8601: "%FT%T%z" } if formats.blank? if formats.is_a?(::Hash) then if !replace then @date_formats ||= {} @date_formats.merge!(formats) else @date_formats = formats end @date_formats.each_pair do |k, v| ::Time::DATE_FORMATS[k] = v end end @date_formats end # Setups strings representation of days and months. # @see DateTime::ClassMethods#days # @see DateTime::ClassMethods#months # @see DateTime#lstrftime # # @param long_months [Array] The string representation of months. # @param short_months [Array] The abbreviated string representation of months. # @param long_days [Array] The string representation of days. # @param short_days [Array] The abbreviated string representation of days. # @return [Hash] The new representations. def setup_date_names(long_months = nil, short_months = nil, long_days = nil, short_days = nil) long_months = self.i18n.date.long_months if long_months.blank? short_months = self.i18n.date.short_months if short_months.blank? long_days = self.i18n.date.long_days if long_days.blank? short_days = self.i18n.date.short_days if short_days.blank? @date_names = { long_months: long_months, short_months: short_months, long_days: long_days, short_days: short_days } end end |
- (Hash) date_formats (readonly)
Custom date and time formats.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/lazier/settings.rb', line 20 class Settings attr_reader :format_number attr_reader :boolean_names attr_reader :date_names attr_reader :date_formats include Lazier::I18n # Returns the singleton instance of the settings. # # @param force [Boolean] If to force recreation of the instance. # @return [Settings] The singleton instance of the settings. def self.instance(force = false) @instance = nil if force @instance ||= self.new end # Initializes a new settings object. def initialize self.i18n_setup(:lazier, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/")) self.setup end # Setups the current instance. def setup self.setup_format_number self.setup_boolean_names self.setup_date_formats self.setup_date_names end # Set the current locale for messages. # # @param locale [String] The new locale. Default is the current system locale. # @return [R18n::Translation] The new translation object. def i18n=(locale) super(locale) self.setup end # Setups formatters for a number. # @see Object#format_number # # @param prec [Fixnum] The precision to show. # @param decimal_separator [String] The string to use as decimal separator. # @param add_string [String] The string to append to the number. # @param k_separator [String] The string to use as thousands separator. # @return [Hash] The new formatters. def setup_format_number(prec = 2, decimal_separator = ".", add_string = "", k_separator = ",") @format_number = { prec: prec, decimal_separator: decimal_separator, add_string: add_string, k_separator: k_separator} end # Setups strings representation of booleans. # @see Object#format_boolean # # @param true_name [String] The string representation of `true`. Defaults to `Yes`. # @param false_name [String] The string representation of `false`. Defaults to `No`. # @return [Hash] The new representations. def setup_boolean_names(true_name = nil, false_name = nil) true_name ||= self.i18n.boolean[0] false_name ||= self.i18n.boolean[1] @boolean_names = {true => true_name, false => false_name} end # Setups custom formats for dates and times. # @see DateTime#lstrftime # # @param formats [Hash] The format to add or replace. # @param replace [Boolean] If to discard current formats. # @return [Hash] The new formats. def setup_date_formats(formats = nil, replace = false) formats = {ct_date: "%Y-%m-%d", ct_time: "%H:%M:%S", ct_date_time: "%F %T", ct_iso_8601: "%FT%T%z" } if formats.blank? if formats.is_a?(::Hash) then if !replace then @date_formats ||= {} @date_formats.merge!(formats) else @date_formats = formats end @date_formats.each_pair do |k, v| ::Time::DATE_FORMATS[k] = v end end @date_formats end # Setups strings representation of days and months. # @see DateTime::ClassMethods#days # @see DateTime::ClassMethods#months # @see DateTime#lstrftime # # @param long_months [Array] The string representation of months. # @param short_months [Array] The abbreviated string representation of months. # @param long_days [Array] The string representation of days. # @param short_days [Array] The abbreviated string representation of days. # @return [Hash] The new representations. def setup_date_names(long_months = nil, short_months = nil, long_days = nil, short_days = nil) long_months = self.i18n.date.long_months if long_months.blank? short_months = self.i18n.date.short_months if short_months.blank? long_days = self.i18n.date.long_days if long_days.blank? short_days = self.i18n.date.short_days if short_days.blank? @date_names = { long_months: long_months, short_months: short_months, long_days: long_days, short_days: short_days } end end |
- (Hash) date_names (readonly)
String representations of days and months.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/lazier/settings.rb', line 20 class Settings attr_reader :format_number attr_reader :boolean_names attr_reader :date_names attr_reader :date_formats include Lazier::I18n # Returns the singleton instance of the settings. # # @param force [Boolean] If to force recreation of the instance. # @return [Settings] The singleton instance of the settings. def self.instance(force = false) @instance = nil if force @instance ||= self.new end # Initializes a new settings object. def initialize self.i18n_setup(:lazier, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/")) self.setup end # Setups the current instance. def setup self.setup_format_number self.setup_boolean_names self.setup_date_formats self.setup_date_names end # Set the current locale for messages. # # @param locale [String] The new locale. Default is the current system locale. # @return [R18n::Translation] The new translation object. def i18n=(locale) super(locale) self.setup end # Setups formatters for a number. # @see Object#format_number # # @param prec [Fixnum] The precision to show. # @param decimal_separator [String] The string to use as decimal separator. # @param add_string [String] The string to append to the number. # @param k_separator [String] The string to use as thousands separator. # @return [Hash] The new formatters. def setup_format_number(prec = 2, decimal_separator = ".", add_string = "", k_separator = ",") @format_number = { prec: prec, decimal_separator: decimal_separator, add_string: add_string, k_separator: k_separator} end # Setups strings representation of booleans. # @see Object#format_boolean # # @param true_name [String] The string representation of `true`. Defaults to `Yes`. # @param false_name [String] The string representation of `false`. Defaults to `No`. # @return [Hash] The new representations. def setup_boolean_names(true_name = nil, false_name = nil) true_name ||= self.i18n.boolean[0] false_name ||= self.i18n.boolean[1] @boolean_names = {true => true_name, false => false_name} end # Setups custom formats for dates and times. # @see DateTime#lstrftime # # @param formats [Hash] The format to add or replace. # @param replace [Boolean] If to discard current formats. # @return [Hash] The new formats. def setup_date_formats(formats = nil, replace = false) formats = {ct_date: "%Y-%m-%d", ct_time: "%H:%M:%S", ct_date_time: "%F %T", ct_iso_8601: "%FT%T%z" } if formats.blank? if formats.is_a?(::Hash) then if !replace then @date_formats ||= {} @date_formats.merge!(formats) else @date_formats = formats end @date_formats.each_pair do |k, v| ::Time::DATE_FORMATS[k] = v end end @date_formats end # Setups strings representation of days and months. # @see DateTime::ClassMethods#days # @see DateTime::ClassMethods#months # @see DateTime#lstrftime # # @param long_months [Array] The string representation of months. # @param short_months [Array] The abbreviated string representation of months. # @param long_days [Array] The string representation of days. # @param short_days [Array] The abbreviated string representation of days. # @return [Hash] The new representations. def setup_date_names(long_months = nil, short_months = nil, long_days = nil, short_days = nil) long_months = self.i18n.date.long_months if long_months.blank? short_months = self.i18n.date.short_months if short_months.blank? long_days = self.i18n.date.long_days if long_days.blank? short_days = self.i18n.date.short_days if short_days.blank? @date_names = { long_months: long_months, short_months: short_months, long_days: long_days, short_days: short_days } end end |
- (Hash) format_number (readonly)
Settings for numbers formatting.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/lazier/settings.rb', line 20 class Settings attr_reader :format_number attr_reader :boolean_names attr_reader :date_names attr_reader :date_formats include Lazier::I18n # Returns the singleton instance of the settings. # # @param force [Boolean] If to force recreation of the instance. # @return [Settings] The singleton instance of the settings. def self.instance(force = false) @instance = nil if force @instance ||= self.new end # Initializes a new settings object. def initialize self.i18n_setup(:lazier, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/")) self.setup end # Setups the current instance. def setup self.setup_format_number self.setup_boolean_names self.setup_date_formats self.setup_date_names end # Set the current locale for messages. # # @param locale [String] The new locale. Default is the current system locale. # @return [R18n::Translation] The new translation object. def i18n=(locale) super(locale) self.setup end # Setups formatters for a number. # @see Object#format_number # # @param prec [Fixnum] The precision to show. # @param decimal_separator [String] The string to use as decimal separator. # @param add_string [String] The string to append to the number. # @param k_separator [String] The string to use as thousands separator. # @return [Hash] The new formatters. def setup_format_number(prec = 2, decimal_separator = ".", add_string = "", k_separator = ",") @format_number = { prec: prec, decimal_separator: decimal_separator, add_string: add_string, k_separator: k_separator} end # Setups strings representation of booleans. # @see Object#format_boolean # # @param true_name [String] The string representation of `true`. Defaults to `Yes`. # @param false_name [String] The string representation of `false`. Defaults to `No`. # @return [Hash] The new representations. def setup_boolean_names(true_name = nil, false_name = nil) true_name ||= self.i18n.boolean[0] false_name ||= self.i18n.boolean[1] @boolean_names = {true => true_name, false => false_name} end # Setups custom formats for dates and times. # @see DateTime#lstrftime # # @param formats [Hash] The format to add or replace. # @param replace [Boolean] If to discard current formats. # @return [Hash] The new formats. def setup_date_formats(formats = nil, replace = false) formats = {ct_date: "%Y-%m-%d", ct_time: "%H:%M:%S", ct_date_time: "%F %T", ct_iso_8601: "%FT%T%z" } if formats.blank? if formats.is_a?(::Hash) then if !replace then @date_formats ||= {} @date_formats.merge!(formats) else @date_formats = formats end @date_formats.each_pair do |k, v| ::Time::DATE_FORMATS[k] = v end end @date_formats end # Setups strings representation of days and months. # @see DateTime::ClassMethods#days # @see DateTime::ClassMethods#months # @see DateTime#lstrftime # # @param long_months [Array] The string representation of months. # @param short_months [Array] The abbreviated string representation of months. # @param long_days [Array] The string representation of days. # @param short_days [Array] The abbreviated string representation of days. # @return [Hash] The new representations. def setup_date_names(long_months = nil, short_months = nil, long_days = nil, short_days = nil) long_months = self.i18n.date.long_months if long_months.blank? short_months = self.i18n.date.short_months if short_months.blank? long_days = self.i18n.date.long_days if long_days.blank? short_days = self.i18n.date.short_days if short_days.blank? @date_names = { long_months: long_months, short_months: short_months, long_days: long_days, short_days: short_days } end end |
- (R18n::Translation) i18n
The translation object.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/lazier/settings.rb', line 20 class Settings attr_reader :format_number attr_reader :boolean_names attr_reader :date_names attr_reader :date_formats include Lazier::I18n # Returns the singleton instance of the settings. # # @param force [Boolean] If to force recreation of the instance. # @return [Settings] The singleton instance of the settings. def self.instance(force = false) @instance = nil if force @instance ||= self.new end # Initializes a new settings object. def initialize self.i18n_setup(:lazier, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/")) self.setup end # Setups the current instance. def setup self.setup_format_number self.setup_boolean_names self.setup_date_formats self.setup_date_names end # Set the current locale for messages. # # @param locale [String] The new locale. Default is the current system locale. # @return [R18n::Translation] The new translation object. def i18n=(locale) super(locale) self.setup end # Setups formatters for a number. # @see Object#format_number # # @param prec [Fixnum] The precision to show. # @param decimal_separator [String] The string to use as decimal separator. # @param add_string [String] The string to append to the number. # @param k_separator [String] The string to use as thousands separator. # @return [Hash] The new formatters. def setup_format_number(prec = 2, decimal_separator = ".", add_string = "", k_separator = ",") @format_number = { prec: prec, decimal_separator: decimal_separator, add_string: add_string, k_separator: k_separator} end # Setups strings representation of booleans. # @see Object#format_boolean # # @param true_name [String] The string representation of `true`. Defaults to `Yes`. # @param false_name [String] The string representation of `false`. Defaults to `No`. # @return [Hash] The new representations. def setup_boolean_names(true_name = nil, false_name = nil) true_name ||= self.i18n.boolean[0] false_name ||= self.i18n.boolean[1] @boolean_names = {true => true_name, false => false_name} end # Setups custom formats for dates and times. # @see DateTime#lstrftime # # @param formats [Hash] The format to add or replace. # @param replace [Boolean] If to discard current formats. # @return [Hash] The new formats. def setup_date_formats(formats = nil, replace = false) formats = {ct_date: "%Y-%m-%d", ct_time: "%H:%M:%S", ct_date_time: "%F %T", ct_iso_8601: "%FT%T%z" } if formats.blank? if formats.is_a?(::Hash) then if !replace then @date_formats ||= {} @date_formats.merge!(formats) else @date_formats = formats end @date_formats.each_pair do |k, v| ::Time::DATE_FORMATS[k] = v end end @date_formats end # Setups strings representation of days and months. # @see DateTime::ClassMethods#days # @see DateTime::ClassMethods#months # @see DateTime#lstrftime # # @param long_months [Array] The string representation of months. # @param short_months [Array] The abbreviated string representation of months. # @param long_days [Array] The string representation of days. # @param short_days [Array] The abbreviated string representation of days. # @return [Hash] The new representations. def setup_date_names(long_months = nil, short_months = nil, long_days = nil, short_days = nil) long_months = self.i18n.date.long_months if long_months.blank? short_months = self.i18n.date.short_months if short_months.blank? long_days = self.i18n.date.long_days if long_days.blank? short_days = self.i18n.date.short_days if short_days.blank? @date_names = { long_months: long_months, short_months: short_months, long_days: long_days, short_days: short_days } end end |
Class Method Details
+ (Settings) instance(force = false)
Returns the singleton instance of the settings.
32 33 34 35 |
# File 'lib/lazier/settings.rb', line 32 def self.instance(force = false) @instance = nil if force @instance ||= self.new end |
Instance Method Details
- (Object) setup
Setups the current instance.
44 45 46 47 48 49 |
# File 'lib/lazier/settings.rb', line 44 def setup self.setup_format_number self.setup_boolean_names self.setup_date_formats self.setup_date_names end |
- (Hash) setup_boolean_names(true_name = nil, false_name = nil)
Setups strings representation of booleans.
78 79 80 81 82 |
# File 'lib/lazier/settings.rb', line 78 def setup_boolean_names(true_name = nil, false_name = nil) true_name ||= self.i18n.boolean[0] false_name ||= self.i18n.boolean[1] @boolean_names = {true => true_name, false => false_name} end |
- (Hash) setup_date_formats(formats = nil, replace = false)
Setups custom formats for dates and times.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/lazier/settings.rb', line 90 def setup_date_formats(formats = nil, replace = false) formats = {ct_date: "%Y-%m-%d", ct_time: "%H:%M:%S", ct_date_time: "%F %T", ct_iso_8601: "%FT%T%z" } if formats.blank? if formats.is_a?(::Hash) then if !replace then @date_formats ||= {} @date_formats.merge!(formats) else @date_formats = formats end @date_formats.each_pair do |k, v| ::Time::DATE_FORMATS[k] = v end end @date_formats end |
- (Hash) setup_date_names(long_months = nil, short_months = nil, long_days = nil, short_days = nil)
Setups strings representation of days and months.
117 118 119 120 121 122 123 124 |
# File 'lib/lazier/settings.rb', line 117 def setup_date_names(long_months = nil, short_months = nil, long_days = nil, short_days = nil) long_months = self.i18n.date.long_months if long_months.blank? short_months = self.i18n.date.short_months if short_months.blank? long_days = self.i18n.date.long_days if long_days.blank? short_days = self.i18n.date.short_days if short_days.blank? @date_names = { long_months: long_months, short_months: short_months, long_days: long_days, short_days: short_days } end |
- (Hash) setup_format_number(prec = 2, decimal_separator = ".", add_string = "", k_separator = ",")
Setups formatters for a number.
68 69 70 |
# File 'lib/lazier/settings.rb', line 68 def setup_format_number(prec = 2, decimal_separator = ".", add_string = "", k_separator = ",") @format_number = { prec: prec, decimal_separator: decimal_separator, add_string: add_string, k_separator: k_separator} end |