module Writetheman::Article::Access

Attributes

date[RW]
str_date[R]
title[RW]

Public Instance Methods

filemane_without_extension() click to toggle source
# File lib/writetheman/article/access.rb, line 31
def filemane_without_extension
  @filename.match(/[^.]*/).to_s
end
filename_from_title() click to toggle source
# 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_filename() click to toggle source
# 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) click to toggle source
# 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!() click to toggle source
# File lib/writetheman/article/access.rb, line 35
def remove_access!
  @title = ''
  @date = nil
  @str_date = ''
end

Private Instance Methods

convert_title_to_filename() click to toggle source
# File lib/writetheman/article/access.rb, line 43
def convert_title_to_filename
   raise 'no title to convert' if @title.nil? || @title.empty?
   I18n.transliterate(@title.gsub(" ", "-").gsub("'", "-").downcase)
end
format_date_file() click to toggle source
# File lib/writetheman/article/access.rb, line 48
def format_date_file          
  raise 'no date to format' if @date.nil? 
  @date.strftime("%Y-%m-%d")
end
format_date_header() click to toggle source
# File lib/writetheman/article/access.rb, line 53
def format_date_header
  raise 'no date to format' if @date.nil? 
  @date.strftime("%Y-%m-%d %H:%M UTC") 
end