Class: Govuk::DummyContentStore::ExampleContentItem

Inherits:
Object
  • Object
show all
Defined in:
lib/govuk/dummy_content_store/example_content_item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ ExampleContentItem

Returns a new instance of ExampleContentItem.



8
9
10
# File 'lib/govuk/dummy_content_store/example_content_item.rb', line 8

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/govuk/dummy_content_store/example_content_item.rb', line 6

def path
  @path
end

Instance Method Details

#base_pathObject



16
17
18
# File 'lib/govuk/dummy_content_store/example_content_item.rb', line 16

def base_path
  data["base_path"]
end

#dataObject



32
33
34
# File 'lib/govuk/dummy_content_store/example_content_item.rb', line 32

def data
  JSON.parse(raw_data)
end

#filenameObject



12
13
14
# File 'lib/govuk/dummy_content_store/example_content_item.rb', line 12

def filename
  File.basename(path)
end

#formatObject



20
21
22
# File 'lib/govuk/dummy_content_store/example_content_item.rb', line 20

def format
  data["format"]
end

#raw_dataObject



36
37
38
# File 'lib/govuk/dummy_content_store/example_content_item.rb', line 36

def raw_data
  File.read(path, encoding: "UTF-8")
end

#titleObject



24
25
26
# File 'lib/govuk/dummy_content_store/example_content_item.rb', line 24

def title
  data["title"]
end

#view_urlObject



28
29
30
# File 'lib/govuk/dummy_content_store/example_content_item.rb', line 28

def view_url
  "/content#{base_path}"
end