Module: Writetheman::Article::Access

Included in:
Base
Defined in:
lib/writetheman/article/access.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dateObject

Returns the value of attribute date.



5
6
7
# File 'lib/writetheman/article/access.rb', line 5

def date
  @date
end

#str_dateObject (readonly)

Returns the value of attribute str_date.



6
7
8
# File 'lib/writetheman/article/access.rb', line 6

def str_date
  @str_date
end

#titleObject

Returns the value of attribute title.



5
6
7
# File 'lib/writetheman/article/access.rb', line 5

def title
  @title
end

Instance Method Details

#filemane_without_extensionObject



31
32
33
# File 'lib/writetheman/article/access.rb', line 31

def filemane_without_extension
  @filename.match(/[^.]*/).to_s
end

#filename_from_titleObject



23
24
25
26
27
28
# File 'lib/writetheman/article/access.rb', line 23

def filename_from_title
  raise 'no title to init filename' if @title.nil? || @title.empty?
  raise 'no date to init filename' if @date.nil? 
  name = convert_title_to_filename
  "#{format_date_file}-#{name}#{@extension}"
end

#init_filenameObject



8
9
10
11
12
# File 'lib/writetheman/article/access.rb', line 8

def init_filename
  raise 'no extension to init filename' if @extension.nil? || @extension.empty?
  @filename = filename_from_title if @filename.nil? || @filename.empty?          
  @filename += @extension if !@filename.include?('.')
end

#init_from_params(params) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/writetheman/article/access.rb', line 14

def init_from_params(params)
  raise 'params are empty to init' if params.nil? || params.empty?
  remove_all!
  @header_params = params['header']        
  @title = @header_params['title']
  @body = params['body']
  @date = DateTime.now if @date.nil? 
end

#remove_access!Object



35
36
37
38
39
# File 'lib/writetheman/article/access.rb', line 35

def remove_access!
  @title = ''
  @date = nil
  @str_date = ''
end