class Wikiscript::Page
Attributes
lang[R]
title[R]
Public Class Methods
get( title, lang: Wikiscript.lang )
click to toggle source
# 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.get ## "force" refresh text (get/fetch/download) o end
new( text=nil, title: nil, lang: Wikiscript.lang )
click to toggle source
# File lib/wikiscript/page.rb, line 25 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
read( path )
click to toggle source
# File lib/wikiscript/page.rb, line 18 def self.read( path ) text = File.open( path, 'r:utf-8' ).read o = new( text, title: "File:#{path}" ) ## use auto-generated File:<path> title path - why? why not? o end
Public Instance Methods
each() { |node| ... }
click to toggle source
# File lib/wikiscript/page.rb, line 43 def each ## loop over all nodes / elements -note: nodes is a (flat) list (array) for now nodes.each do |node| yield( node ) end end
get()
click to toggle source
# File lib/wikiscript/page.rb, line 50 def get ## "force" refresh text (get/fetch/download) @nodes = nil ## note: reset cached parsed nodes too @text = Client.new.text( @title, lang: @lang ) @text end
nodes()
click to toggle source
# File lib/wikiscript/page.rb, line 39 def nodes @nodes ||= parse # cache text (from parse) end
parse()
click to toggle source
# File lib/wikiscript/page.rb, line 60 def parse ## todo/change: use/find a different name e.g. doc/elements/etc. - why? why not? @nodes = PageReader.parse( text ) @nodes end
text()
click to toggle source
# File lib/wikiscript/page.rb, line 35 def text @text ||= get # cache text (from request) end