Class: Pollex::Entry
- Inherits:
-
PollexObject
- Object
- PollexObject
- Pollex::Entry
- Extended by:
- PollexClass
- Defined in:
- lib/pollex/entry.rb
Overview
A Pollex entry, corresponding to a reflex for a reconstruction, with a language and a source.
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#flag ⇒ Object
Returns the value of attribute flag.
-
#language_name ⇒ Object
Returns the value of attribute language_name.
-
#language_path ⇒ Object
writeonly
Sets the attribute language_path.
-
#reconstruction_name ⇒ Object
Returns the value of attribute reconstruction_name.
-
#reconstruction_path ⇒ Object
writeonly
Sets the attribute reconstruction_path.
-
#reflex ⇒ Object
Returns the value of attribute reflex.
-
#source_code ⇒ Object
Returns the value of attribute source_code.
-
#source_path ⇒ Object
writeonly
Sets the attribute source_path.
Attributes included from PollexClass
Class Method Summary collapse
-
.find(name) ⇒ Array<Entry>
Looks up all Entries matching a given name.
Instance Method Summary collapse
-
#language ⇒ Language
The Language corresponding to this entry.
-
#path ⇒ (String, nil)
The path to this entry, if given.
-
#reconstruction ⇒ (Reconstruction, nil)
The Reconstruction corresponding to this entry, if given.
-
#source ⇒ (Source, nil)
The Source corresponding to this entry, if given.
-
#terms ⇒ Array<String>
Processes the description of this entry and extracts a lits of definitions, translated into English if necessary.
Methods included from PollexClass
Methods inherited from PollexObject
Constructor Details
This class inherits a constructor from Pollex::PollexObject
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
6 7 8 |
# File 'lib/pollex/entry.rb', line 6 def description @description end |
#flag ⇒ Object
Returns the value of attribute flag.
6 7 8 |
# File 'lib/pollex/entry.rb', line 6 def flag @flag end |
#language_name ⇒ Object
Returns the value of attribute language_name.
6 7 8 |
# File 'lib/pollex/entry.rb', line 6 def language_name @language_name end |
#language_path=(value) ⇒ Object (writeonly)
Sets the attribute language_path
8 9 10 |
# File 'lib/pollex/entry.rb', line 8 def language_path=(value) @language_path = value end |
#reconstruction_name ⇒ Object
Returns the value of attribute reconstruction_name.
6 7 8 |
# File 'lib/pollex/entry.rb', line 6 def reconstruction_name @reconstruction_name end |
#reconstruction_path=(value) ⇒ Object (writeonly)
Sets the attribute reconstruction_path
7 8 9 |
# File 'lib/pollex/entry.rb', line 7 def reconstruction_path=(value) @reconstruction_path = value end |
#reflex ⇒ Object
Returns the value of attribute reflex.
6 7 8 |
# File 'lib/pollex/entry.rb', line 6 def reflex @reflex end |
#source_code ⇒ Object
Returns the value of attribute source_code.
6 7 8 |
# File 'lib/pollex/entry.rb', line 6 def source_code @source_code end |
#source_path=(value) ⇒ Object (writeonly)
Sets the attribute source_path
9 10 11 |
# File 'lib/pollex/entry.rb', line 9 def source_path=(value) @source_path = value end |
Class Method Details
.find(name) ⇒ Array<Entry>
Looks up all Entries matching a given name.
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/pollex/entry.rb', line 77 def self.find(name) Scraper.instance.get_all(Entry, "/search/?field=entry&query=#{name}", [ [:reflex, 'td[3]/text()'], [:description, 'td[4]/text()'], [:language_path, 'td[1]/a/@href'], [:language_name, 'td[1]/a/text()'], [:reconstruction_path, 'td[2]/a/@href'], [:reconstruction_name, 'td[2]/a/text()', lambda {|x| x.split('.')[1..-1].join('.')}], [:flag, "td[3]/span[@class='flag']/text()"] ]) end |
Instance Method Details
#language ⇒ Language
Returns the Language corresponding to this entry.
46 47 48 49 50 51 52 |
# File 'lib/pollex/entry.rb', line 46 def language if @language_path @language ||= Language.new(:name => @language_name, :path => @language_path) else nil end end |
#path ⇒ (String, nil)
In some Pollex listings, entries’ paths are not listed.
Returns the path to this entry, if given.
14 15 16 |
# File 'lib/pollex/entry.rb', line 14 def path @reconstruction_path end |
#reconstruction ⇒ (Reconstruction, nil)
In some Pollex listings, entries’ reconstructions are not listed.
Returns the Reconstruction corresponding to this entry, if given.
66 67 68 69 70 71 72 |
# File 'lib/pollex/entry.rb', line 66 def reconstruction if @reconstruction_path @reconstruction ||= Reconstruction.new(:protoform => @reconstruction_name, :path => @reconstruction_path) else nil end end |
#source ⇒ (Source, nil)
In some Pollex listings, entries’ sources are not listed.
Returns the Source corresponding to this entry, if given.
56 57 58 59 60 61 62 |
# File 'lib/pollex/entry.rb', line 56 def source if @source_path @source ||= Source.new(:code => @source_code, :path => @source_path) else nil end end |
#terms ⇒ Array<String>
Processes the description of this entry and extracts a lits of definitions, translated into English if necessary.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/pollex/entry.rb', line 21 def terms string = @description grammar = description_grammar # trim last part of description, if necessary if grammar[:trim_after] string = string.split(grammar[:trim_after])[0] end # split into terms, remove any unnecessary expressions terms = string.split(grammar[:dividers]) .map {|t| t.sub(grammar[:trim_expressions], '') .strip .capitalize } .select {|t| t.match(/\w/) } # attempt to translate to English if necessary if grammar[:language] != 'en' terms.map! {|t| Translator.instance.translate(t, grammar[:language], terms) } end terms end |