Class: Content

Inherits:
Object
  • Object
show all
Includes:
Configuration
Defined in:
lib/content.rb

Direct Known Subclasses

HamlContent, MdContent

Instance Method Summary collapse

Methods included from Configuration

#config, config, #defaultLinks, defaultLinks, links_file_path, read_config, read_configuration, read_default_links, valid_location?

Constructor Details

#initialize(file_path, child = nil) ⇒ Content

Returns a new instance of Content.



9
10
11
12
13
14
15
16
17
18
# File 'lib/content.rb', line 9

def initialize file_path, child = nil
  @file_path = file_path
  @plain_content = ""
  @datas = Hash.new
  @cats = ""
  @child = child
  @content = content

  read_content
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



36
37
38
39
40
41
42
43
44
# File 'lib/content.rb', line 36

def method_missing(m, *args, &block)
  if m =~ /^(.*)\?$/
    return @datas.has_key? $1
  elsif @datas.has_key? m.to_s
    return @datas[m.to_s]
  else
    return nil
  end
end

Instance Method Details

#account(name) ⇒ Object



76
77
78
79
# File 'lib/content.rb', line 76

def  name
  return nil unless account? name
  return config["accounts"][name]
end

#account?(name) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
74
# File 'lib/content.rb', line 71

def account? name
  return false unless config.has_key? "accounts"
  return config["accounts"].has_key? name
end

#childObject



20
21
22
# File 'lib/content.rb', line 20

def child
  @child
end

#contentObject



24
25
26
27
28
29
30
# File 'lib/content.rb', line 24

def content
  c = self
  while !c.child.nil?
    c = c.child
  end
  c
end

#datasObject



58
59
60
# File 'lib/content.rb', line 58

def datas
  @datas
end

#dirObject



32
33
34
# File 'lib/content.rb', line 32

def dir
  File.dirname @file_path
end

#gravatarObject



66
67
68
69
# File 'lib/content.rb', line 66

def gravatar
  hash = Digest::MD5.hexdigest(email)
  "http://www.gravatar.com/avatar/#{hash}"
end

#gravatar?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/content.rb', line 62

def gravatar?
  email?
end

#raw_contentObject



46
47
48
# File 'lib/content.rb', line 46

def raw_content
  @plain_content
end

#urlObject



54
55
56
# File 'lib/content.rb', line 54

def url
  @url ||= ''
end

#url=(url) ⇒ Object



50
51
52
# File 'lib/content.rb', line 50

def url= url
  @url = url
end