Class: Hermaeus::Apocryphon

Inherits:
Object
  • Object
show all
Defined in:
lib/hermaeus/apocryphon.rb

Overview

Public: Data structure describing a Compendium entry.

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Apocryphon

Public: Constructs an Apocryphon from reddit data responses.

data - A Hash emitted by Client#get_posts



7
8
9
# File 'lib/hermaeus/apocryphon.rb', line 7

def initialize data
	@data = data
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object

Public: Permit method-style access to the underlying data Hash’s keys.



19
20
21
# File 'lib/hermaeus/apocryphon.rb', line 19

def method_missing name, *args, &block
	@data[name.to_sym]
end

Instance Method Details

#htmlObject

Public: Accessor for the Apocryphon’s HTML as compiled by reddit.



29
30
31
# File 'lib/hermaeus/apocryphon.rb', line 29

def html
	data[:selftext_html]
end

#textObject

Public: Accessor for the Apocryphon’s Markdown text.



24
25
26
# File 'lib/hermaeus/apocryphon.rb', line 24

def text
	@data[:selftext]
end

#to_sObject

Public: Serializes the Apocryphon item to a string.

Returns a String containing the title and author.



14
15
16
# File 'lib/hermaeus/apocryphon.rb', line 14

def to_s
	"#{self.title} – by #{self.author}"
end