module Neruda::OrgFileExtracter
This module holds extracter methods for the {Neruda::OrgFile} class.
Private Instance Methods
extract_data()
click to toggle source
Main method, which will call the other to initialize an
{Neruda::OrgFile} instance.
# File lib/neruda/org_file/extracter.rb, line 10 def extract_data @content = IO.read @file @title = extract_title @subtitle = extract_subtitle @date = extract_date @author = extract_author @keywords = extract_keywords @lang = extract_lang @excerpt = extract_excerpt end
extract_date()
click to toggle source
# File lib/neruda/org_file/extracter.rb, line 21 def extract_date timerx = '([0-9:]{5})(?::([0-9]{2}))?' m = /^#\+date: *<([0-9-]{10}) [\w.]+(?: #{timerx})?> *$/i.match(@content) return nil if m.nil? @notime = m[2].nil? if @notime time = '00:00:00' else time = "#{m[2]}:#{m[3] || '00'}" end DateTime.strptime("#{m[1]} #{time}", '%Y-%m-%d %H:%M:%S') end
extract_excerpt()
click to toggle source
# File lib/neruda/org_file/extracter.rb, line 68 def extract_excerpt @content.scan(/^#\+description:(.+)$/i).map { |l| l[0].strip }.join(' ') end
extract_keywords()
click to toggle source
# File lib/neruda/org_file/extracter.rb, line 56 def extract_keywords m = /^#\+keywords:(.+)$/i.match(@content) return [] if m.nil? m[1].split(',').map(&:strip) end
extract_lang()
click to toggle source
# File lib/neruda/org_file/extracter.rb, line 62 def extract_lang m = /^#\+language:(.+)$/i.match(@content) return Neruda::Config.settings['lang'] if m.nil? m[1].strip end
extract_subtitle()
click to toggle source
# File lib/neruda/org_file/extracter.rb, line 44 def extract_subtitle m = /^#\+subtitle:(.+)$/i.match(@content) return '' if m.nil? m[1].strip end
extract_title()
click to toggle source
# File lib/neruda/org_file/extracter.rb, line 34 def extract_title m = /^#\+title:(.+)$/i.match(@content) if m.nil? # Avoid to leak absolute path project_relative_path = @file.sub(/^#{Dir.pwd}\//, '') return project_relative_path end m[1].strip end