class PhraseLookup::Master

Public Class Methods

new(h={}) click to toggle source
# File lib/phrase_lookup.rb, line 61
def initialize(h={})

  @h = h
  
end

Public Instance Methods

create(s) click to toggle source
# File lib/phrase_lookup.rb, line 67
def create(s)
  
  @h = parse_log(s)
  
end
create_from_txt(s) click to toggle source
# File lib/phrase_lookup.rb, line 73
def create_from_txt(s)
  
  @h = parse(s)
  
end
parse(raw_s) click to toggle source
# File lib/phrase_lookup.rb, line 93
def parse(raw_s)
  
  s, _ = RXFHelper.read(raw_s)       
  
  a = s.downcase.gsub(/\?/,'').lines.map(&:strip).compact
  a.uniq.inject({}) {|r,x| r.merge x => a.count(x)}
  
end
parse_array(a) click to toggle source
# File lib/phrase_lookup.rb, line 102
def parse_array(a)
       
  @h = a.map {|x| x.downcase.gsub(/\?/,'')}\
      .inject({}) {|r,x| r.merge x => a.count(x)}
  
end
parse_log(raw_s) click to toggle source
# File lib/phrase_lookup.rb, line 109
def parse_log(raw_s)
  
  s, _ = RXFHelper.read(raw_s)       
  
  a = s.downcase.gsub(/\?/,'').lines.map do |x| 
    phrase = x.strip[/(?<=: )[^|]+(?= )/i]
    phrase.length < 50 ? phrase : nil if phrase
  end.compact
  
  a.uniq.inject({}) {|r,x| r.merge x => a.count(x)}
  
end
save(filename='master.yaml') click to toggle source
# File lib/phrase_lookup.rb, line 85
def save(filename='master.yaml')
  File.write filename, @h.sort.to_h.to_yaml
end
to_h() click to toggle source
# File lib/phrase_lookup.rb, line 89
def to_h()
  @h.clone
end
update(s) click to toggle source
# File lib/phrase_lookup.rb, line 79
def update(s)

  parse_log(s).each {|k,v| @h.has_key?(k) ? @h[k] += v : @h[k] = v }

end