Class: Kang::Data

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

Instance Method Summary collapse

Constructor Details

#initialize(reg_text = "", match_text = "") ⇒ Data

Returns a new instance of Data.



28
29
30
31
# File 'lib/kang.rb', line 28

def initialize(reg_text="",match_text="")
  update_regexp(reg_text)
  update_match_string(match_text)
end

Instance Method Details

#match?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/kang.rb', line 67

def match?
  @match ? true : false
end

#match_beginObject



71
72
73
74
75
76
77
# File 'lib/kang.rb', line 71

def match_begin
  if @match
    @match.begin(0)
  else
    nil
  end
end

#match_endObject



79
80
81
82
83
84
85
# File 'lib/kang.rb', line 79

def match_end
  if @match
    @match.end(0)
  else
    nil
  end
end

#match_group_countObject



46
47
48
49
50
51
52
# File 'lib/kang.rb', line 46

def match_group_count
  if @match
    @match.length
  else
    nil
  end
end

#matchesObject



87
88
89
90
91
92
93
# File 'lib/kang.rb', line 87

def matches
  if @match and (@match.length > 1)
    @match.to_a
  else
    []
  end
end

#regexp_valid?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/kang.rb', line 63

def regexp_valid?
  @re.nil? ? false : true
end

#update_matchObject



38
39
40
41
42
43
44
# File 'lib/kang.rb', line 38

def update_match
  if @re
    @match = @re.match(@match_string)
  else
    @match = nil
  end
end

#update_match_string(match_string) ⇒ Object



33
34
35
36
# File 'lib/kang.rb', line 33

def update_match_string(match_string)
  @match_string = match_string
  update_match
end

#update_regexp(re_string) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/kang.rb', line 54

def update_regexp(re_string)
  begin
    @re = Regexp.new(re_string)
  rescue RegexpError
    @re = nil
  end
  update_match
end