Class: Lazier::Settings
- Inherits:
-
Object
- Object
- Lazier::Settings
- Defined in:
- lib/lazier/settings.rb
Overview
Settings for the extensions.
Instance Attribute Summary (collapse)
-
- (Object) boolean_names
readonly
String representations of booleans.
-
- (Object) date_formats
readonly
Custom date and time formats.
-
- (Object) date_names
readonly
String representations of days and months.
-
- (Object) format_number
readonly
Settings for numbers formatting.
Class Method Summary (collapse)
-
+ (Settings) instance
Returns the singleton instance of the settings.
Instance Method Summary (collapse)
-
- (Settings) initialize
constructor
Initializes a new settings object.
-
- (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.
Constructor Details
- (Settings) initialize
Initializes a new settings object.
30 31 32 33 34 35 |
# File 'lib/lazier/settings.rb', line 30 def initialize self.setup_format_number self.setup_boolean_names self.setup_date_formats self.setup_date_names end |
Instance Attribute Details
- (Object) boolean_names (readonly)
String representations of booleans.
14 15 16 |
# File 'lib/lazier/settings.rb', line 14 def boolean_names @boolean_names end |
- (Object) date_formats (readonly)
Custom date and time formats.
20 21 22 |
# File 'lib/lazier/settings.rb', line 20 def date_formats @date_formats end |
- (Object) date_names (readonly)
String representations of days and months.
17 18 19 |
# File 'lib/lazier/settings.rb', line 17 def date_names @date_names end |
- (Object) format_number (readonly)
Settings for numbers formatting.
11 12 13 |
# File 'lib/lazier/settings.rb', line 11 def format_number @format_number end |
Class Method Details
+ (Settings) instance
Returns the singleton instance of the settings.
25 26 27 |
# File 'lib/lazier/settings.rb', line 25 def self.instance @instance ||= self.new end |
Instance Method Details
- (Hash) setup_boolean_names(true_name = nil, false_name = nil)
Setups strings representation of booleans.
60 61 62 63 64 |
# File 'lib/lazier/settings.rb', line 60 def setup_boolean_names(true_name = nil, false_name = nil) true_name ||= "Yes" false_name ||= "No" @boolean_names = {true => true_name, false => false_name} end |
- (Hash) setup_date_formats(formats = nil, replace = false)
Setups custom formats for dates and times.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/lazier/settings.rb', line 72 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.
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/lazier/settings.rb', line 104 def setup_date_names(long_months = nil, short_months = nil, long_days = nil, short_days = nil) long_months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] if long_months.blank? short_months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] if short_months.blank? long_days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] if long_days.blank? short_days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] 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.
45 46 47 48 49 50 51 52 |
# File 'lib/lazier/settings.rb', line 45 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 |