Class: LookLike::Support
- Inherits:
-
Object
- Object
- LookLike::Support
- Defined in:
- lib/look_like/support.rb
Constant Summary collapse
- @@DATE_CHARS =
/[DMYHSmhs\d]/
- @@DATE_STAMP_REGEX =
/^[\/x]+$/
- @@TIME_STAMP_REGEX =
/^[\/x\-\:TZ\s]+$/
Class Method Summary collapse
- .amount?(string) ⇒ Boolean
- .amount_def?(expected) ⇒ Boolean
- .currency_of(amount) ⇒ Object
- .date?(stamp) ⇒ Boolean
- .email?(string) ⇒ Boolean
- .enum?(string) ⇒ Boolean
- .enum_values(list) ⇒ Object
- .loose_url?(string) ⇒ Boolean
- .mask_date(stamp) ⇒ Object
- .normalize_currency(amount) ⇒ Object
- .time?(stamp) ⇒ Boolean
- .url?(string) ⇒ Boolean
Class Method Details
.amount?(string) ⇒ Boolean
17 18 19 20 |
# File 'lib/look_like/support.rb', line 17 def self.amount?(string) rounded = string.sub(".", ",").strip /^\$[\s]*[\d,]+\d$/ === rounded end |
.amount_def?(expected) ⇒ Boolean
13 14 15 16 |
# File 'lib/look_like/support.rb', line 13 def self.amount_def?(string) rounded = string.sub(".", ",").strip /^\$[\s]*[\d,]+\d$/ === rounded end |
.currency_of(amount) ⇒ Object
37 38 39 |
# File 'lib/look_like/support.rb', line 37 def self.currency_of(amount) amount.end_with?("amount") ? amount.split("amount")[0].strip : amount[/^[^\d]+/].strip end |
.date?(stamp) ⇒ Boolean
57 58 59 |
# File 'lib/look_like/support.rb', line 57 def self.date?(stamp) stamp.include?("x") && @@DATE_STAMP_REGEX === stamp end |
.email?(string) ⇒ Boolean
45 46 47 |
# File 'lib/look_like/support.rb', line 45 def self.email?(string) string.include?("@") && !string.include?("/") && loose_url?(string) end |
.enum?(string) ⇒ Boolean
26 27 28 |
# File 'lib/look_like/support.rb', line 26 def self.enum?(string) /^[^\/]+[\/][^\/]/ === string end |
.enum_values(list) ⇒ Object
41 42 43 |
# File 'lib/look_like/support.rb', line 41 def self.enum_values(list) list.split("/").map{|value| value.strip()} end |
.loose_url?(string) ⇒ Boolean
30 31 32 33 34 35 |
# File 'lib/look_like/support.rb', line 30 def self.loose_url?(string) if(string.strip.length && string.include?(".")) string = "http://" + string end !!(string =~ /\A#{URI::regexp}\z/) end |
.mask_date(stamp) ⇒ Object
61 62 63 |
# File 'lib/look_like/support.rb', line 61 def self.mask_date(stamp) stamp.gsub(@@DATE_CHARS, "x") end |
.normalize_currency(amount) ⇒ Object
22 23 24 |
# File 'lib/look_like/support.rb', line 22 def self.normalize_currency(amount) (amount.nil? || amount.empty?) ? "" : amount.sub(currency_of(amount), "$") end |
.time?(stamp) ⇒ Boolean
53 54 55 |
# File 'lib/look_like/support.rb', line 53 def self.time?(stamp) stamp.include?("x") && @@TIME_STAMP_REGEX === stamp end |
.url?(string) ⇒ Boolean
9 10 11 |
# File 'lib/look_like/support.rb', line 9 def self.url?(string) !!(string =~ /\A#{URI::regexp}\z/) end |