Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/core_ext/string.rb

Instance Method Summary collapse

Instance Method Details

#date_to_aryArray

Returns:



16
17
18
# File 'lib/core_ext/string.rb', line 16

def date_to_ary
  self.split("").map!(&:parse_date)
end

#parse_dateDate

Returns:

  • (Date)


6
7
8
9
10
11
12
13
# File 'lib/core_ext/string.rb', line 6

def parse_date
  self.scan(/(\d+)(月)(\d+)(日)/)
  month = $1.to_i
  day = $3.to_i
  today = Date.today
  year = today.month >= 10 && month == 1 ? today.year + 1 : today.year
  Date.parse("#{year}.#{month}.#{day}")
end

#phone_number?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/core_ext/string.rb', line 20

def phone_number?
  delete('-') =~ /^\d+$/
end