writetheman 0.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -38,8 +38,9 @@ module Writetheman
38
38
  remove_access!
39
39
  @filename = filename
40
40
  read
41
- @title = @header_params['title']
42
- @date = Date.parse(@header_params['date'])
41
+ #@title = @header_params['title']
42
+ #@date = Date.parse(@header_params['date'])
43
+ init_header_params
43
44
  end
44
45
 
45
46
  def load_from_title(title, date)
@@ -41,9 +41,19 @@ module Writetheman
41
41
  @header_params['date'] = format_date_header if !header_params.include?('date')
42
42
  @header_params['title'] = @title if !header_params.include?('title')
43
43
 
44
- @title = @header_params['title'] if @title.nil?
45
- @str_date = @header_params['date'] if @str_date.nil?
46
- @tags = @header_params['tags'] if @header_params.include?('tags')
44
+ @title = @header_params['title'] if @title.nil? || @title.empty?
45
+ @str_date = @header_params['date'] if @str_date.nil? || @str_date.empty?
46
+ begin
47
+ @date = str_date_to_object if @date.nil? && !@str_date.nil? && !@str_date.empty?
48
+ rescue
49
+ puts "WARNING : can't convert the string date '#{@str_date}' to a date object when initialize article #{@title}"
50
+ @date = nil
51
+ end
52
+ @tags = @header_params['tags'] if (@tags.nil? || @tags.empty?) && @header_params.include?('tags')
53
+ end
54
+
55
+ def str_date_to_object
56
+ DateTime.strptime(@str_date, "%Y-%m-%d %H:%M")
47
57
  end
48
58
 
49
59
  def init_header_params_from_content # get_header_params_from_content
@@ -1,3 +1,3 @@
1
1
  module Writetheman
2
- VERSION = "0.2"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -65,8 +65,10 @@ describe Writetheman::Article::Base do
65
65
  describe "access" do
66
66
  it do
67
67
  article.load_from_file(filename)
68
+ article.all_content.should eq( content )
68
69
  article.title.should eq(title)
69
70
  article.date.strftime("%Y-%m-%d").should eq(date.strftime("%Y-%m-%d"))
71
+ article.tags.should eq(tags)
70
72
  end
71
73
  end
72
74
 
@@ -74,6 +76,9 @@ describe Writetheman::Article::Base do
74
76
  it do
75
77
  article.load_from_file(filename)
76
78
  article.all_content.should eq( content )
79
+ article.title.should eq(title)
80
+ article.date.strftime("%Y-%m-%d").should eq(date.strftime("%Y-%m-%d"))
81
+ article.tags.should eq(tags)
77
82
  end
78
83
  end
79
84
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: writetheman
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-30 00:00:00.000000000 Z
12
+ date: 2014-01-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler