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
# File 'lib/ubi/thema.rb', line 12

def initialize(name, urls = [], opts = {})
  @name = name
  @urls = urls
  @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

#[](arg) ⇒ Object



37
38
39
# File 'lib/ubi/thema.rb', line 37

def [](arg)
  @cache[arg]
end

#araneasObject



20
21
22
# File 'lib/ubi/thema.rb', line 20

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

#reduce_namesObject



24
25
26
27
28
# File 'lib/ubi/thema.rb', line 24

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

#specObject



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

def spec
  puts self
  Ubi.memorias.each do |memoria|
    print Paint[memoria.name, :black]
    puts self[memoria.key]
  end
end

#to_sObject



58
59
60
# File 'lib/ubi/thema.rb', line 58

def to_s
  name
end

#try_consultor(a) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/ubi/thema.rb', line 49

def try_consultor(a)
  a = a.new(self)
  Ubi.memorias.each do |m|
    puts Paint["Trying to find #{m} in #{a.class}", :green]
    @cache[m] = matches = m.parse(a.datum)
    puts matches if matches && !matches.empty?
  end
end