Class: Wikiscript::Page

Inherits:
Object
  • Object
show all
Includes:
LogUtils::Logging
Defined in:
lib/wikiscript/page.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text = nil, title: nil, lang: Wikiscript.lang) ⇒ Page



19
20
21
22
23
24
25
26
27
# File 'lib/wikiscript/page.rb', line 19

def initialize( text=nil, title: nil, lang: Wikiscript.lang )
  ## todo: check title
  ## replace title spaces w/ _ ????
  ##  to allow "pretty" titles - why? why not??

  @text  = text
  @title = title
  @lang  = lang
end

Instance Attribute Details

#langObject (readonly)

Returns the value of attribute lang.



9
10
11
# File 'lib/wikiscript/page.rb', line 9

def lang
  @lang
end

#titleObject (readonly)

Returns the value of attribute title.



9
10
11
# File 'lib/wikiscript/page.rb', line 9

def title
  @title
end

Class Method Details

.get(title, lang: Wikiscript.lang) ⇒ Object

todo/check: add a fetch/download alias - why? why not?



12
13
14
15
16
# File 'lib/wikiscript/page.rb', line 12

def self.get( title, lang: Wikiscript.lang )    ## todo/check: add a fetch/download alias - why? why not?
  o = new( title: title, lang: lang )
  ## o.text   ## "force" download / fetch
  o
end

Instance Method Details

#download_textObject



33
34
35
# File 'lib/wikiscript/page.rb', line 33

def download_text
  Client.new.text( @title, lang: @lang )
end

#parseObject

todo/change: use/find a different name e.g. doc/elements/etc. - why? why not?



37
38
39
# File 'lib/wikiscript/page.rb', line 37

def parse   ## todo/change: use/find a different name e.g. doc/elements/etc. - why? why not?
  PageReader.parse( text )
end

#textObject



29
30
31
# File 'lib/wikiscript/page.rb', line 29

def text
  @text ||= download_text   # cache text (from request)
end