Class: Ubi::Thema

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::AttributeMethods, ActiveModel::Dirty, ActiveModel::Serialization
Defined in:
lib/ubi/thema.rb

Overview

Thema -> subject, matter, case

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, urls = [], opts = {}) ⇒ Thema

Returns a new instance of Thema.



12
13
14
15
16
17
18
19
20
# File 'lib/ubi/thema.rb', line 12

def initialize(name, urls = [], opts = {})
  @name = name
  @urls = urls
  @name ||= urls.first.split('.').first.gsub(%r{^\w+://}, '')
  @urls = @urls.map { |url| url =~ %r{://} ? url : "http://#{url}" }
  @opts = opts
  @cache = Ubi.memorias.reduce({}) { |a, e| a.merge(e => opts[e]) }
  reduce_names
end

Instance Attribute Details

#asciiObject

Returns the value of attribute ascii.



10
11
12
# File 'lib/ubi/thema.rb', line 10

def ascii
  @ascii
end

#cleanObject

Returns the value of attribute clean.



10
11
12
# File 'lib/ubi/thema.rb', line 10

def clean
  @clean
end

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/ubi/thema.rb', line 10

def name
  @name
end

#optsObject

Returns the value of attribute opts.



10
11
12
# File 'lib/ubi/thema.rb', line 10

def opts
  @opts
end

#urlsObject

Returns the value of attribute urls.



10
11
12
# File 'lib/ubi/thema.rb', line 10

def urls
  @urls
end

Instance Method Details

#araneasObject



22
23
24
# File 'lib/ubi/thema.rb', line 22

def araneas
  @araneas ||= urls.map { |u| Aranea.new(self, u) }
end

#reduce_namesObject



26
27
28
29
30
31
# File 'lib/ubi/thema.rb', line 26

def reduce_names
  return unless name
  @ascii = name.mb_chars.downcase
  @downcase = name.mb_chars.downcase
  @clean = @downcase.gsub(/\W/, ' ')
end

#specObject



41
42
43
44
45
46
47
48
# File 'lib/ubi/thema.rb', line 41

def spec
  puts self
  Ubi.memorias.each do |memoria|
    d = send(memoria.plural)
    puts Paint["#{memoria.name} (#{d.size})", :black]
    puts d
  end
end

#to_sObject



62
63
64
# File 'lib/ubi/thema.rb', line 62

def to_s
  name
end

#try_datum(a) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ubi/thema.rb', line 50

def try_datum(a)
  Ubi.memorias.each do |m|
    print Paint["Trying to find #{m} in page ", :green]
    matches = m.parse(a)
    puts Paint[matches.size, :black]
    next unless matches && !matches.empty?
    matches.each do |match|
      send(m.plural) << match unless send(m.plural).include?(match)
    end
  end
end