Class: Array
- Defined in:
- lib/corelib/array/math.rb,
lib/corelib/array/core.rb,
lib/corelib/array/alias.rb,
lib/corelib/array/helpers.rb
Overview
options = => ‘default’.merge(options)
Class Method Summary collapse
- .date_format_options(options = {}) ⇒ Object
- .date_format_options_exemplified_raw(options = {}) ⇒ Object
- .date_format_options_raw(options = {}) ⇒ Object
- .month_options(options = {}) ⇒ Object
- .month_options_abbrev_raw(start = 1) ⇒ Object
- .month_options_raw(start = 1) ⇒ Object
- .time_clock_type_options(options = {}) ⇒ Object
- .us_state_options(options = {}) ⇒ Object
- .us_state_options_abbrev_raw ⇒ Object
- .us_state_options_raw ⇒ Object
Instance Method Summary collapse
- #add_all(arr, options = {}) ⇒ Object
- #add_blank_option(options = {}) ⇒ Object
-
#each_with_end_flag ⇒ Object
This method iterates over the Array as normal #each method.
- #extract_options! ⇒ Object
- #format_options_list(options = {}) ⇒ Object
- #not_empty? ⇒ Boolean
- #options_label_for(value) ⇒ Object
- #sum(options = {}) ⇒ Object
- #to_yes_no(options = {}) ⇒ Object
Class Method Details
.date_format_options(options = {}) ⇒ Object
22 23 24 25 |
# File 'lib/corelib/array/helpers.rb', line 22 def self.(={}) exemplify = .fetch(:exemplify, true) exemplify ? () : () end |
.date_format_options_exemplified_raw(options = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/corelib/array/helpers.rb', line 32 def self.(={}) id = .fetch(:start_id, 1) t = Time.now s = .fetch(:separater, " - ") d = .fetch(:day, t.strftime("%d")) m = .fetch(:month, t.strftime("%m")) y = .fetch(:year, t.year) [["MM/DD/YYYY#{s}(#{m}/#{d}/#{y})", id], ["MM-DD-YYYY#{s}(#{m}-#{d}-#{y})", id+1], ["DD/MM/YYYY#{s}(#{d}/#{m}/#{y})", id+2], ["DD-MM-YYYY#{s}(#{d}-#{m}-#{y})", id+3], ["YYYY/MM/DD#{s}(#{y}/#{m}/#{d})", id+4], ["YYYY-MM-DD#{s}(#{y}-#{m}-#{d})", id+5], ["DD.MM.YYYY#{s}(#{d}.#{m}.#{y})", id+6], ["YYYY.MM.DD#{s}(#{y}.#{m}.#{d})", id+7]] end |
.date_format_options_raw(options = {}) ⇒ Object
27 28 29 30 |
# File 'lib/corelib/array/helpers.rb', line 27 def self.(={}) id = .fetch(:start_id, 1) [["MM/DD/YYYY", id], ["MM-DD-YYYY", id+1], ["DD/MM/YYYY", id+2], ["DD-MM-YYYY", id+3], ["YYYY/MM/DD", id+4], ["YYYY-MM-DD", id+5], ["DD.MM.YYYY", id+6], ["YYYY.MM.DD", id+7]] end |
.month_options(options = {}) ⇒ Object
43 44 45 46 47 |
# File 'lib/corelib/array/helpers.rb', line 43 def self.(={}) abbrev = .fetch(:abbrev, false) list = abbrev ? : list.() end |
.month_options_abbrev_raw(start = 1) ⇒ Object
54 55 56 57 |
# File 'lib/corelib/array/helpers.rb', line 54 def self.(start=1) [["Jan", start], ["Feb", start + 1], ["Mar", start + 2], ["Apr", start + 3], ["May", start + 4], ["Jun", start + 5], ["Jul", start + 6], ["Aug", start + 7], ["Sep", start + 8], ["Oct", start + 9], ["Nov", start + 10], ["Dec", start + 11]] end |
.month_options_raw(start = 1) ⇒ Object
49 50 51 52 |
# File 'lib/corelib/array/helpers.rb', line 49 def self.(start=1) [["January", start], ["February", start + 1], ["March", start + 2], ["April", start + 3], ["May", start + 4], ["June", start + 5], ["July", start + 6], ["August", start + 7], ["September", start + 8], ["October", start + 9], ["November", start + 10], ["December", start + 11]] end |
.time_clock_type_options(options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/corelib/array/helpers.rb', line 8 def self.(={}) exemplify = .fetch(:exemplify, true) id = .fetch(:start_id, 1) return [["12-Hour Clock", id], ["24-Hour Clock", id+1]] if !exemplify t = Time.now s = .fetch(:separater, " - ") h = .fetch(:day, t.strftime("%l")) m = .fetch(:month, t.strftime("%m")) ap =.fetch(:am_pm, t.strftime("%P")) hm = .fetch(:day24, t.strftime("%H")) [["12-Hour Clock#{s}(#{h}:#{m}#{ap})", id], ["24-Hour Clock#{s}(#{hm}:#{m})", id+1]] end |
.us_state_options(options = {}) ⇒ Object
59 60 61 62 63 |
# File 'lib/corelib/array/helpers.rb', line 59 def self.(={}) abbrev = .fetch(:abbrev, false) list = abbrev ? : list.() end |
.us_state_options_abbrev_raw ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/corelib/array/helpers.rb', line 77 def self. [['AL', 'AL'], ['AK', 'AK'], ['AZ', 'AZ'], ['AR', 'AR'], ['CA', 'CA'], ['CO', 'CO'], ['CT', 'CT'], ['DC', 'DC'], ['DE', 'DE'], ['FL', 'FL'], ['GA', 'GA'], ['HI', 'HI'], ['ID', 'ID'], ['IL', 'IL'], ['IN', 'IN'], ['IA', 'IA'], ['KS', 'KS'], ['KY', 'KY'], ['LA', 'LA'], ['ME', 'ME'], ['MD', 'MD'], ['MA', 'MA'], ['MI', 'MI'], ['MN', 'MN'], ['MS', 'MS'], ['MO', 'MO'], ['MT', 'MT'], ['NE', 'NE'], ['NV', 'NV'], ['NH', 'NH'], ['NJ', 'NJ'], ['NM', 'NM'], ['NY', 'NY'], ['NC', 'NC'], ['ND', 'ND'], ['OH', 'OH'], ['OK', 'OK'], ['OR', 'OR'], ['PA', 'PA'], ['RI', 'RI'], ['SC', 'SC'], ['SD', 'SD'], ['TN', 'TN'], ['TX', 'TX'], ['UT', 'UT'], ['VT', 'VT'], ['VA', 'VA'], ['WA', 'WA'], ['WV', 'WV'], ['WI', 'WI'], ['WY', 'WY'],] end |
.us_state_options_raw ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/corelib/array/helpers.rb', line 65 def self. [['Alabama', 'AL'], ['Alaska', 'AK'], ['Arizona', 'AZ'], ['Arkansas', 'AR'], ['California', 'CA'], ['Colorado', 'CO'], ['Connecticut', 'CT'], ['D.C.', 'DC'], ['Delaware', 'DE'], ['Florida', 'FL'], ['Georgia', 'GA'], ['Hawaii', 'HI'], ['Idaho', 'ID'], ['Illinois', 'IL'], ['Indiana', 'IN'], ['Iowa', 'IA'], ['Kansas', 'KS'], ['Kentucky', 'KY'], ['Louisiana', 'LA'], ['Maine', 'ME'], ['Maryland', 'MD'], ['Massachusetts', 'MA'], ['Michigan', 'MI'], ['Minnesota', 'MN'], ['Mississippi', 'MS'], ['Missouri', 'MO'], ['Montana', 'MT'], ['Nebraska', 'NE'], ['Nevada', 'NV'], ['New Hampshire', 'NH'], ['New Jersey', 'NJ'], ['New Mexico', 'NM'], ['New York', 'NY'], ['North Carolina', 'NC'], ['North Dakota', 'ND'], ['Ohio', 'OH'], ['Oklahoma', 'OK'], ['Oregon', 'OR'], ['Pennsylvania', 'PA'], ['Rhode Island', 'RI'], ['South Carolina', 'SC'], ['South Dakota', 'SD'], ['Tennessee', 'TN'], ['Texas', 'TX'], ['Utah', 'UT'], ['Vermont', 'VT'], ['Virginia', 'VA'], ['Washington', 'WA'], ['West Virginia', 'WV'], ['Wisconsin', 'WI'], ['Wyoming', 'WY']] end |
Instance Method Details
#add_all(arr, options = {}) ⇒ Object
33 34 35 36 37 |
# File 'lib/corelib/array/core.rb', line 33 def add_all(arr, ={}) flatten = .fetch(:flatten, true) a = flatten ? arr.flatten : arr self.concat(a) end |
#add_blank_option(options = {}) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/corelib/array/core.rb', line 11 def add_blank_option(={}) doit = .fetch(:doit, true) value = .fetch(:value, 0) label = .fetch(:label, "") self.insert(0, [label, value]) if doit self end |
#each_with_end_flag ⇒ Object
This method iterates over the Array as normal #each method. For each iteration set two variables in the block, |item, flag|. item will be set tot he current item in the iteration; flag will be set to “false” on all iterations except the last iteration
22 23 24 25 26 27 |
# File 'lib/corelib/array/core.rb', line 22 def each_with_end_flag my_size = self.size self.each_with_index do |item, index| index + 1 == my_size ? yield(item, true) : yield(item, false) end end |
#extract_options! ⇒ Object
3 4 5 |
# File 'lib/corelib/array/core.rb', line 3 def last.is_a?(::Hash) ? pop : {} end |
#format_options_list(options = {}) ⇒ Object
89 90 91 92 93 |
# File 'lib/corelib/array/helpers.rb', line 89 def (={}) () () if [:format] #Change case if :format is set, otherwise use default case self end |
#not_empty? ⇒ Boolean
29 30 31 |
# File 'lib/corelib/array/core.rb', line 29 def not_empty? !self.empty? end |
#options_label_for(value) ⇒ Object
3 4 5 6 |
# File 'lib/corelib/array/helpers.rb', line 3 def (value) sub = self.find {|each| each[1] == value} sub.nil? ? nil : sub[0] end |
#sum(options = {}) ⇒ Object
5 6 7 8 |
# File 'lib/corelib/array/math.rb', line 5 def sum ( = {}) strict = .fetch(:strict, true) strict ? sum_strict : sum_loose end |
#to_yes_no(options = {}) ⇒ Object
7 8 9 |
# File 'lib/corelib/array/core.rb', line 7 def to_yes_no(={}) self.collect {|e| e.to_yes_no()} end |