Class: EverExp::Html

Inherits:
Object
  • Object
show all
Defined in:
lib/ever_exp/html.rb,
lib/ever_exp/heading.rb

Defined Under Namespace

Classes: Heading

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Html

Returns a new instance of Html.



11
12
13
14
# File 'lib/ever_exp/html.rb', line 11

def initialize path
  @html = File.open(path) { |f| Nokogiri::HTML(f) }
  @location = path
end

Instance Attribute Details

#htmlObject (readonly)

Returns the value of attribute html.



8
9
10
# File 'lib/ever_exp/html.rb', line 8

def html
  @html
end

#locationObject (readonly)

Returns the value of attribute location.



8
9
10
# File 'lib/ever_exp/html.rb', line 8

def location
  @location
end

#note=(value) ⇒ Object (writeonly)

Sets the attribute note

Parameters:

  • value

    the value to set the attribute note to.



9
10
11
# File 'lib/ever_exp/html.rb', line 9

def note=(value)
  @note = value
end

Instance Method Details

#attachmentsObject



57
58
59
60
61
# File 'lib/ever_exp/html.rb', line 57

def attachments
  _content.
	css('a').
	select{|a| a.css('img').count > 0}
end

#code_blocksObject



47
48
49
50
51
# File 'lib/ever_exp/html.rb', line 47

def code_blocks
  html.
    css('div').
    select { |div| div.attr('style') =~ /^-en-codeblock/ }
end

#contentObject



63
64
65
# File 'lib/ever_exp/html.rb', line 63

def content
  _content.to_html
end

#createdObject



37
38
39
40
# File 'lib/ever_exp/html.rb', line 37

def created
  parse_meta
  @created
end

#headingObject



71
72
73
74
75
76
77
78
79
# File 'lib/ever_exp/html.rb', line 71

def heading
  return @heading if @heading
  h = Heading.new
  heading_elements.each do |b|
    level, title = level_title b
    h.add level, title
  end
  @heading = h.to_h
end

#heading?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/ever_exp/html.rb', line 67

def heading?
  not heading.empty?
end

#heading_elementsObject



81
82
83
# File 'lib/ever_exp/html.rb', line 81

def heading_elements
  _content.css('div > b, div > span > b')
end

#imgsObject



53
54
55
# File 'lib/ever_exp/html.rb', line 53

def imgs
  html.css('img')
end

#isHtml?Boolean

Returns:

  • (Boolean)


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

def isHtml?
  true
end

#nameObject



16
17
18
# File 'lib/ever_exp/html.rb', line 16

def name
  File.basename(location).gsub(/\.html$/, '')
end

#tagsObject



28
29
30
31
# File 'lib/ever_exp/html.rb', line 28

def tags
  parse_meta
  @tags
end

#tags_arrayObject



33
34
35
# File 'lib/ever_exp/html.rb', line 33

def tags_array
  tags.split ', '
end

#titleObject



24
25
26
# File 'lib/ever_exp/html.rb', line 24

def title
  @title ||= html.title
end

#updatedObject



42
43
44
45
# File 'lib/ever_exp/html.rb', line 42

def updated
  parse_meta
  @updated
end