Class: KanjiMaster::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/kanji_master/reader.rb

Instance Method Summary collapse

Instance Method Details

#alphabet?(text) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/kanji_master/reader.rb', line 3

def alphabet?(text)
  !(RegexConstant::NON_ENGLISH_REGEX === text)
end

#kanji?(text) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/kanji_master/reader.rb', line 15

def kanji?(text)
  RegexConstant::KANJI_REGEX === text
end

#maybe_kanji?(text) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/kanji_master/reader.rb', line 11

def maybe_kanji?(text)
  !alphabet?(text)
end

#number?(text) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/kanji_master/reader.rb', line 7

def number?(text)
  (RegexConstant::NUMBER_REGEX === text)
end

#postal_code?(text) ⇒ Boolean

Returns:

  • (Boolean)


20
# File 'lib/kanji_master/reader.rb', line 20

def postal_code?(text); zipcode?(text) end

#postcode?(text) ⇒ Boolean

Returns:

  • (Boolean)


21
# File 'lib/kanji_master/reader.rb', line 21

def postcode?(text); zipcode?(text) end

#read_text(text) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/kanji_master/reader.rb', line 26

def read_text(text)
  matched_kanji = text.match(RegexConstant::KANJI_REGEX)

  text_analyse             = {}
  text_analyse[:full_text] = text
  text_analyse[:alphabets] = text.tr('^A-Za-z', '')
  text_analyse[:numbers]   = text.tr('^0-9', '')
  text_analyse[:kanjis]    = matched_kanji[0] if matched_kanji

  Text.new(text_analyse)
end

#zip_code?(text) ⇒ Boolean

Returns:

  • (Boolean)


19
# File 'lib/kanji_master/reader.rb', line 19

def zip_code?(text); zipcode?(text) end

#zipcode?(text) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/kanji_master/reader.rb', line 22

def zipcode?(text)
  RegexConstant::JP_ZIPCODE_REGEX === text
end