Class: Pollex::Language

Inherits:
PollexObject show all
Extended by:
PollexClass
Defined in:
lib/pollex/language.rb

Overview

A Polynesian language with entries in Pollex.

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

#codeString

Returns the Language’s abbreviated code.

Returns:

  • (String)

    the Language’s abbreviated code



25
26
27
# File 'lib/pollex/language.rb', line 25

def code
  @code ||= self.all.find {|l| l.name == @name}.code
end

#countInteger

Returns number of Entries belonging to this Language.

Returns:

  • (Integer)

    number of Entries belonging to this Language



30
31
32
33
34
# File 'lib/pollex/language.rb', line 30

def count
  @count ||= Scraper.instance.get(@path, [
    [:count, "p[@class='count']/text()", lambda {|x| x.split(' ').first}]
  ])[:count].to_i
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#pathObject

Returns the value of attribute path.



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

def path
  @path
end

Class Method Details

.allArray<Language>

Returns all Languages in Pollex.

Returns:

  • (Array<Language>)

    array of Languages in Pollex



38
39
40
41
42
43
44
45
# File 'lib/pollex/language.rb', line 38

def self.all
  @languages ||= Scraper.instance.get_all(Language, "/language/", [
    [:name, 'td[2]/a/text()'],
    [:path, 'td[1]/a/@href'],
    [:code, 'td[1]/a/text()'],
    [:count, 'td[3]/text()']
  ])
end

.countInteger

Counts the number of Languages within Pollex

Returns:

  • (Integer)

    number of Languages in Pollex



49
50
51
# File 'lib/pollex/language.rb', line 49

def self.count
  self.all.count
end

.find(name) ⇒ Array<Language>

Looks up all Languages matching a given name.

Parameters:

  • name (String)

    term to search for

Returns:

  • (Array<Language>)

    array of Languages matching the search term



56
57
58
59
60
61
# File 'lib/pollex/language.rb', line 56

def self.find(name)
  Scraper.instance.get_all(Language, "/search/?field=language&query=#{name}", [
    [:name, 'td[1]/a/text()'],
    [:path, 'td[1]/a/@href']
  ])
end

Instance Method Details

#entriesArray<Entry>

Returns all Entries belonging to this Language

Returns:

  • (Array<Entry>)

    array of Entries belonging to this Language



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/pollex/language.rb', line 12

def entries
  @entries ||= Scraper.instance.get_all(Entry, @path, [
    [:reflex, 'td[2]/text()'],
    [:description, 'td[3]/text()'],
    [:language_name, nil, lambda {|x| @name}],
    [:language_path, nil, lambda {|x| @path}],
    [:source_code, 'td[4]/a/text()'],
    [:source_path, 'td[4]/a/@href'],
    [:flag, "td[3]/span[@class='flag']/text()"]
 ])
end