Class: Ubi::Thema
- Inherits:
-
Object
- Object
- Ubi::Thema
- Includes:
- ActiveModel::AttributeMethods, ActiveModel::Dirty, ActiveModel::Serialization
- Defined in:
- lib/ubi/thema.rb
Overview
Thema -> subject, matter, case
Instance Attribute Summary collapse
-
#ascii ⇒ Object
Returns the value of attribute ascii.
-
#clean ⇒ Object
Returns the value of attribute clean.
-
#name ⇒ Object
Returns the value of attribute name.
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#urls ⇒ Object
Returns the value of attribute urls.
Instance Method Summary collapse
- #araneas ⇒ Object
-
#initialize(name, urls = [], opts = {}) ⇒ Thema
constructor
A new instance of Thema.
- #reduce_names ⇒ Object
- #spec ⇒ Object
- #to_s ⇒ Object
- #try_datum(a) ⇒ Object
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
#ascii ⇒ Object
Returns the value of attribute ascii.
10 11 12 |
# File 'lib/ubi/thema.rb', line 10 def ascii @ascii end |
#clean ⇒ Object
Returns the value of attribute clean.
10 11 12 |
# File 'lib/ubi/thema.rb', line 10 def clean @clean end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/ubi/thema.rb', line 10 def name @name end |
#opts ⇒ Object
Returns the value of attribute opts.
10 11 12 |
# File 'lib/ubi/thema.rb', line 10 def opts @opts end |
#urls ⇒ Object
Returns the value of attribute urls.
10 11 12 |
# File 'lib/ubi/thema.rb', line 10 def urls @urls end |
Instance Method Details
#araneas ⇒ Object
22 23 24 |
# File 'lib/ubi/thema.rb', line 22 def araneas @araneas ||= urls.map { |u| Aranea.new(self, u) } end |
#reduce_names ⇒ Object
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 |
#spec ⇒ Object
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_s ⇒ Object
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 |