Module: C12
- Defined in:
- lib/c12-commons/ka.rb,
lib/c12-commons/core.rb,
lib/c12-commons/email.rb,
lib/c12-commons/mobile.rb,
lib/c12-commons/version.rb
Defined Under Namespace
Class Method Summary collapse
-
.compact_mobile(mob) ⇒ Object
მობილურის “კომპაქტიზაცია”: ტოვებს მხოლოდ ციფრებს.
- .correct_email?(email) ⇒ Boolean
-
.correct_mobile?(mob) ⇒ Boolean
ამოწმებს მობილურის ნომრის კორექტულობას.
-
.empty?(value) ⇒ Boolean
Determines emptiness of the argument.
-
.format_mobile(mob) ⇒ Object
აფორმატებს მობილურს (XXX)XXX-XXX სახით.
-
.number_format(number, precision = 2) ⇒ Object
Format number using given precission.
-
.nvl(value, value_if_nil = 0) ⇒ Object
Returns the first argument unless it’s
nil, in which case the second argument is returned.
Class Method Details
.compact_mobile(mob) ⇒ Object
მობილურის “კომპაქტიზაცია”: ტოვებს მხოლოდ ციფრებს.
4 5 6 |
# File 'lib/c12-commons/mobile.rb', line 4 def self.compact_mobile(mob) mob.scan(/[0-9]/).join('') if mob end |
.correct_email?(email) ⇒ Boolean
3 4 5 |
# File 'lib/c12-commons/email.rb', line 3 def self.correct_email?(email) not not (email =~ /^\S+@\S+$/) end |
.correct_mobile?(mob) ⇒ Boolean
ამოწმებს მობილურის ნომრის კორექტულობას. კორექტული მობილურის ნომერი უნდა შეიცავდეს 9 ციფრს.
10 11 12 |
# File 'lib/c12-commons/mobile.rb', line 10 def self.correct_mobile?(mob) not not (compact_mobile(mob) =~ /^[0-9]{9}$/) end |
.empty?(value) ⇒ Boolean
Determines emptiness of the argument.
nil is empty, '' is empty, empty Array or Array of nils is empty. Other objects are empty if they respond to empty? command and it returns true. In other cases the object is not empty.
17 18 19 20 21 22 23 |
# File 'lib/c12-commons/core.rb', line 17 def self.empty?(value) return true if value.nil? return value.strip.empty? if value.instance_of? String return value.compact.empty? if value.instance_of? Array return value.empty? if value.respond_to? :empty? false end |
.format_mobile(mob) ⇒ Object
აფორმატებს მობილურს (XXX)XXX-XXX სახით.
15 16 17 18 |
# File 'lib/c12-commons/mobile.rb', line 15 def self.format_mobile(mob) mob = C12.compact_mobile(mob) "(#{mob[0..2]})#{mob[3..5]}-#{mob[6..8]}" end |
.number_format(number, precision = 2) ⇒ Object
Format number using given precission. Number is formatted using Georgian conventions for decimal and thousands separators.
27 28 29 |
# File 'lib/c12-commons/core.rb', line 27 def self.number_format(number, precision = 2) C12::KA.number(number, :precision => precision) end |
.nvl(value, value_if_nil = 0) ⇒ Object
Returns the first argument unless it’s nil, in which case the second argument is returned.
7 8 9 |
# File 'lib/c12-commons/core.rb', line 7 def self.nvl(value, value_if_nil = 0) value.nil? ? value_if_nil : value end |