Class: Pollex::Entry

Inherits:
PollexObject show all
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

Attributes included from PollexClass

#inspectables

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PollexClass

attr_inspector

Methods inherited from PollexObject

#initialize, #inspect

Constructor Details

This class inherits a constructor from Pollex::PollexObject

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



6
7
8
# File 'lib/pollex/entry.rb', line 6

def description
  @description
end

#flagObject

Returns the value of attribute flag.



6
7
8
# File 'lib/pollex/entry.rb', line 6

def flag
  @flag
end

#language_nameObject

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

Parameters:

  • value

    the value to set the attribute language_path to.



8
9
10
# File 'lib/pollex/entry.rb', line 8

def language_path=(value)
  @language_path = value
end

#reconstruction_nameObject

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

Parameters:

  • value

    the value to set the attribute reconstruction_path to.



7
8
9
# File 'lib/pollex/entry.rb', line 7

def reconstruction_path=(value)
  @reconstruction_path = value
end

#reflexObject

Returns the value of attribute reflex.



6
7
8
# File 'lib/pollex/entry.rb', line 6

def reflex
  @reflex
end

#source_codeObject

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

Parameters:

  • value

    the value to set the attribute source_path to.



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.

Parameters:

  • name (String)

    term to search for

Returns:

  • (Array<Entry>)

    array of Entries matching the search term



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

#languageLanguage

Returns the Language corresponding to this entry.

Returns:

  • (Language)

    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)

Note:

In some Pollex listings, entries’ paths are not listed.

Returns the path to this entry, if given.

Returns:

  • ((String, nil))

    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)

Note:

In some Pollex listings, entries’ reconstructions are not listed.

Returns the Reconstruction corresponding to this entry, if given.

Returns:

  • ((Reconstruction, nil))

    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)

Note:

In some Pollex listings, entries’ sources are not listed.

Returns the Source corresponding to this entry, if given.

Returns:

  • ((Source, nil))

    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

#termsArray<String>

Processes the description of this entry and extracts a lits of definitions, translated into English if necessary.

Returns:

  • (Array<String>)

    definitions corresponding to this entry



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