noir 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bdf37cb436e6fa50b65f833bcecc28b459fc4c8f
4
- data.tar.gz: b7186bffbd09eca787d78040bbbbe9f4edd823d5
3
+ metadata.gz: 37c60ade454a8bfe945bcdc6aa9f227675cbc191
4
+ data.tar.gz: 913ccc77f719e326d6a6a0624e11903ec4c9d403
5
5
  SHA512:
6
- metadata.gz: 2e454b33b7edd35c77c371d645dc3e30763edea37205c8d7fd5d08094a3ba97391c05d2f500509000413160d60c1c5e1ba333c8118428bf64f629e90eaf2e255
7
- data.tar.gz: 9ab600c4cecc3ebec37933465269081c58f784f4258e36c88ff139b87b1ac73c8db598004bb1f547072ee01922e269746687318f1242c8280488f5ca3dd8da6d
6
+ metadata.gz: b426b2c916464cde1309f7097d45b3062bdbb7de12e51da7a78755b4175a62359f389695b5600cacf588bdf99f57357a78ba9287b89b86f3773f5d971679d86d
7
+ data.tar.gz: abe489c1566ea84dafe714926359719a6219aa5676f82bd2e3cd102a373b21a5658741c0dbbd2867389d00a1871832bda538d0184e5c9aac4f739b7e25a14e14
@@ -3,6 +3,7 @@ require 'noir/options'
3
3
  require 'noir/executer'
4
4
  require 'noir/base'
5
5
  require 'noir/base/terminal_command'
6
+ require 'noir/util'
6
7
  require 'noir/command'
7
8
 
8
9
  module Noir
@@ -16,3 +16,4 @@ require 'noir/command/edit'
16
16
  require 'noir/command/format'
17
17
  require 'noir/command/help'
18
18
  require 'noir/command/new'
19
+ require 'noir/command/summarize'
@@ -1,47 +1,31 @@
1
1
  class Noir::Command::Edit::WeeklyReport < Noir::Base::Command
2
2
  @description = 'edit weekly report'
3
3
 
4
- class << self
5
- # time utilities
6
-
7
- TimeOfADay = (24 * 60 * 60)
8
- TimeFormat = '%Y%m%d'
9
-
10
- def end_of_week_separeted separator_day_of_week, week_diff
11
- check_method_name = "#{separator_day_of_week}?"
12
- unless Time.instance_methods(false).include?(check_method_name.to_sym)
13
- raise "a day of week name is incorrect! : #{separator_day_of_week}"
14
- end
15
-
16
- week_end = Time.now + (week_diff * 7 * TimeOfADay)
17
- week_end += TimeOfADay
18
- while !week_end.send(check_method_name)
19
- week_end += TimeOfADay
20
- end
21
- week_end - TimeOfADay
22
- end
23
-
24
- def begin_of_week_separeted separator_day_of_week, week_diff
25
- end_of_week_separeted(separator_day_of_week, week_diff) - (6*TimeOfADay)
26
- end
4
+ extend Noir::Util::Weekly
5
+ TimeFormat = '%Y%m%d'
27
6
 
7
+ def self.report_name separator_day_of_week, week_diff=0
8
+ [begin_of_week_separeted(separator_day_of_week, week_diff).strftime(TimeFormat),
9
+ end_of_week_separeted(separator_day_of_week, week_diff).strftime(TimeFormat)].join('_')
10
+ end
28
11
 
29
- # main methods
30
- def edit_report separator_day_of_week, week_diff=0
31
- system("vim #{report_name(separator_day_of_week, week_diff)}.txt")
32
- end
12
+ # main method
13
+ def self.edit_report separator_day_of_week, week_diff=0
14
+ system("vim #{report_name(separator_day_of_week, week_diff)}.txt")
15
+ end
16
+ end
33
17
 
34
- def report_name separator_day_of_week, week_diff=0
35
- [begin_of_week_separeted(separator_day_of_week, week_diff).strftime(TimeFormat),
36
- end_of_week_separeted(separator_day_of_week, week_diff).strftime(TimeFormat)].join('_')
18
+ [:monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday].each do |day|
19
+ clazz = Class.new(Noir::Base::TerminalCommand)
20
+ clazz.class_eval do
21
+ @description = "edit weekly report separated by #{day}"
22
+ @day_of_week = day
23
+ end
24
+ clazz.class_eval do
25
+ def self.execute *args
26
+ week_diff = args.first.to_i || 0
27
+ Noir::Command::Edit::WeeklyReport.edit_report @day_of_week, week_diff
37
28
  end
38
29
  end
30
+ Noir::Command::Edit::WeeklyReport.const_set(day.capitalize, clazz)
39
31
  end
40
-
41
- require 'noir/command/edit/weekly_report/monday'
42
- require 'noir/command/edit/weekly_report/tuesday'
43
- require 'noir/command/edit/weekly_report/wednesday'
44
- require 'noir/command/edit/weekly_report/thursday'
45
- require 'noir/command/edit/weekly_report/friday'
46
- require 'noir/command/edit/weekly_report/saturday'
47
- require 'noir/command/edit/weekly_report/sunday'
@@ -1,12 +1,13 @@
1
1
  class Noir::Command::New::Note < Noir::Base::TerminalCommand
2
- @description = 'create empty txt. filename format is <serial-no>_<date>.txt'
2
+ @description = 'Create empty txt. filename format is <serial-no>_<date>.txt'
3
3
 
4
- TimeFormat = '%Y%m%d'
4
+ TimeFormat = '%Y%m%d'
5
+ FileNameGlob = '[0-9]*_????????.txt'
5
6
 
6
7
  class << self
7
8
 
8
9
  def create_new_note
9
- note_num = Dir.glob('[0-9]*_????????.txt').size + 1
10
+ note_num = Dir.glob(FileNameGlob).size + 1
10
11
  note_name = format("%02d", note_num) + '_' + Time.now.strftime(TimeFormat) + '.txt'
11
12
  Noir::Command::New.createFile note_name
12
13
  return note_name
@@ -0,0 +1,5 @@
1
+ class Noir::Command::Summarize < Noir::Base::Command
2
+ @description = 'summarize utilities'
3
+ end
4
+
5
+ require 'noir/command/summarize/note'
@@ -0,0 +1,5 @@
1
+ class Noir::Command::Summarize::Note < Noir::Base::Command
2
+ @description = 'summarize notes'
3
+ end
4
+
5
+ require 'noir/command/summarize/note/weekly'
@@ -0,0 +1,30 @@
1
+ class Noir::Command::Summarize::Note::Weekly < Noir::Base::Command
2
+ @description = 'summarize notes weekly'
3
+
4
+ extend Noir::Util::Weekly
5
+ TimeFormat = '%Y%m%d'
6
+
7
+ def self.summarize_by_week separator_day_of_week, week_diff=0
8
+ begin_note = begin_of_week_separeted(separator_day_of_week, week_diff).strftime(TimeFormat)
9
+ end_note = end_of_week_separeted(separator_day_of_week, week_diff).strftime(TimeFormat)
10
+
11
+ note_names = (begin_note..end_note).map{|n| Dir.glob("*#{n}*").first}.compact
12
+ puts note_names.flat_map {|name| ['-----' + name + '-----', File.read(name) ]}.join("\n")
13
+ end
14
+ end
15
+
16
+ # Sub commands: specific day of week
17
+ [:monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday].each do |day|
18
+ clazz = Class.new(Noir::Base::TerminalCommand)
19
+ clazz.class_eval do
20
+ @description = "summarize notes weekly separated by #{day}"
21
+ @day_of_week = day
22
+ end
23
+ clazz.class_eval do
24
+ def self.execute *args
25
+ week_diff = args.first.to_i || 0
26
+ Noir::Command::Summarize::Note::Weekly.summarize_by_week @day_of_week, week_diff
27
+ end
28
+ end
29
+ Noir::Command::Summarize::Note::Weekly.const_set(day.capitalize, clazz)
30
+ end
@@ -0,0 +1,6 @@
1
+ module Noir
2
+ module Util
3
+ end
4
+ end
5
+
6
+ require 'noir/util/weekly'
@@ -0,0 +1,23 @@
1
+ module Noir::Util::Weekly
2
+ # utilities for calculation weeks
3
+
4
+ TimeOfADay = (24 * 60 * 60)
5
+
6
+ def end_of_week_separeted separator_day_of_week, week_diff
7
+ check_method_name = "#{separator_day_of_week}?"
8
+ unless Time.instance_methods(false).include?(check_method_name.to_sym)
9
+ raise "a day of week name is incorrect! : #{separator_day_of_week}"
10
+ end
11
+
12
+ week_end = Time.now + (week_diff * 7 * TimeOfADay)
13
+ week_end += TimeOfADay
14
+ while !week_end.send(check_method_name)
15
+ week_end += TimeOfADay
16
+ end
17
+ week_end - TimeOfADay
18
+ end
19
+
20
+ def begin_of_week_separeted separator_day_of_week, week_diff
21
+ end_of_week_separeted(separator_day_of_week, week_diff) - (6*TimeOfADay)
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module Noir
2
- VERSION = '0.1.7'
2
+ VERSION = '0.1.8'
3
3
  end
@@ -11,4 +11,22 @@ describe 'Noir::Command::New::Note' do
11
11
  expect(Noir::Command::New).to receive(:createFile)
12
12
  expect{Noir::Command::New::Note.execute}.to output.to_stdout
13
13
  end
14
+
15
+ it 'is support empty directory' do
16
+ allow(Dir).to receive(:glob).with(anything).and_return([])
17
+ expect(Noir::Command::New).to receive(:createFile)
18
+ expect{Noir::Command::New::Note.execute}.to output(/^01_.*txt$/).to_stdout
19
+ end
20
+
21
+ it 'is support directory include few files' do
22
+ allow(Dir).to receive(:glob).with(anything).and_return(10.times.to_a)
23
+ expect(Noir::Command::New).to receive(:createFile)
24
+ expect{Noir::Command::New::Note.execute}.to output(/^11_.*txt$/).to_stdout
25
+ end
26
+
27
+ it 'is support directory include over 100 files' do
28
+ allow(Dir).to receive(:glob).with(anything).and_return(120.times.to_a)
29
+ expect(Noir::Command::New).to receive(:createFile)
30
+ expect{Noir::Command::New::Note.execute}.to output(/^121_.*txt$/).to_stdout
31
+ end
14
32
  end
@@ -0,0 +1,43 @@
1
+ require 'noir'
2
+ require 'spec_helper'
3
+
4
+ describe 'Noir::Command::Summarize::Note::Weekly' do
5
+ include_context :dependencie_on_current_directory
6
+
7
+ it 'is inherited Noir::Base::Command' do
8
+ expect(Noir::Command::Summarize::Note::Weekly.superclass).to eq(Noir::Base::Command)
9
+ end
10
+
11
+ describe '.summarize_by_week' do
12
+ before do
13
+ File.write('01_20140401.txt', 'hoge') # 2014/04/01(Tue)
14
+ File.write('02_20140402.txt', 'fuga') # 2014/04/02(Wed)
15
+ File.write('03_20140403.txt', 'piyo') # 2014/04/03(Thu)
16
+ end
17
+
18
+ it 'include texts in .txt file' do
19
+ expect{Noir::Command::Summarize::Note::Weekly.summarize_by_week(:tuesday)}.to output(/hoge/).to_stdout
20
+ end
21
+
22
+ it 'include all texts in weekly range' do
23
+ expect{Noir::Command::Summarize::Note::Weekly.summarize_by_week(:monday)}.to output(/hoge/).to_stdout
24
+ expect{Noir::Command::Summarize::Note::Weekly.summarize_by_week(:monday)}.to output(/fuga/).to_stdout
25
+ expect{Noir::Command::Summarize::Note::Weekly.summarize_by_week(:monday)}.to output(/piyo/).to_stdout
26
+ end
27
+
28
+ it 'not include texts without weekly range' do
29
+ expect{Noir::Command::Summarize::Note::Weekly.summarize_by_week(:wednesday)}.to output(/hoge/).to_stdout
30
+ expect{Noir::Command::Summarize::Note::Weekly.summarize_by_week(:wednesday)}.not_to output(/fuga/).to_stdout
31
+ expect{Noir::Command::Summarize::Note::Weekly.summarize_by_week(:wednesday)}.not_to output(/piyo/).to_stdout
32
+ end
33
+ end
34
+
35
+ describe 'sub commands' do
36
+ [:monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday].each do |day|
37
+ it 'is inherited Noir::Base::TerminalCommand' do
38
+ sub_command = Noir::Command::Summarize::Note::Weekly.const_get day.capitalize
39
+ expect(sub_command.superclass).to eq(Noir::Base::TerminalCommand)
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,9 @@
1
+ require 'noir'
2
+ require 'spec_helper'
3
+
4
+ describe 'Noir::Command::Summarize::Note' do
5
+ it 'is inherited Noir::Base::Command' do
6
+ expect(Noir::Command::Summarize::Note.superclass).to eq(Noir::Base::Command)
7
+ end
8
+ end
9
+
@@ -0,0 +1,10 @@
1
+ require 'noir'
2
+ require 'spec_helper'
3
+
4
+ describe 'Noir::Command::Summarize' do
5
+ it 'is inherited Noir::Base::Command' do
6
+ expect(Noir::Command::Summarize.superclass).to eq(Noir::Base::Command)
7
+ end
8
+ end
9
+
10
+
@@ -41,3 +41,23 @@ def stub_commands
41
41
  =end
42
42
 
43
43
  end
44
+
45
+ shared_context :dependencie_on_current_directory do
46
+ around do |spec|
47
+ Dir.mktmpdir('noir-tempdir') do |dir|
48
+ Dir.chdir(dir) do
49
+ spec.run
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ # for ruby 1.9.2
56
+
57
+ unless File.respond_to?(:write)
58
+ class File
59
+ def self.write filename, contents
60
+ open(filename, 'w'){|f| f.write(contents)}
61
+ end
62
+ end
63
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: noir
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - atton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-27 00:00:00.000000000 Z
11
+ date: 2015-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -92,13 +92,6 @@ files:
92
92
  - lib/noir/command/edit.rb
93
93
  - lib/noir/command/edit/note.rb
94
94
  - lib/noir/command/edit/weekly_report.rb
95
- - lib/noir/command/edit/weekly_report/friday.rb
96
- - lib/noir/command/edit/weekly_report/monday.rb
97
- - lib/noir/command/edit/weekly_report/saturday.rb
98
- - lib/noir/command/edit/weekly_report/sunday.rb
99
- - lib/noir/command/edit/weekly_report/thursday.rb
100
- - lib/noir/command/edit/weekly_report/tuesday.rb
101
- - lib/noir/command/edit/weekly_report/wednesday.rb
102
95
  - lib/noir/command/format.rb
103
96
  - lib/noir/command/format/pdf_url.rb
104
97
  - lib/noir/command/help.rb
@@ -110,8 +103,13 @@ files:
110
103
  - lib/noir/command/new/makefile.rb
111
104
  - lib/noir/command/new/makefile/tex.rb
112
105
  - lib/noir/command/new/note.rb
106
+ - lib/noir/command/summarize.rb
107
+ - lib/noir/command/summarize/note.rb
108
+ - lib/noir/command/summarize/note/weekly.rb
113
109
  - lib/noir/executer.rb
114
110
  - lib/noir/options.rb
111
+ - lib/noir/util.rb
112
+ - lib/noir/util/weekly.rb
115
113
  - lib/noir/version.rb
116
114
  - noir.gemspec
117
115
  - spec/noir/command/calculate/time_spec.rb
@@ -138,6 +136,9 @@ files:
138
136
  - spec/noir/command/new/makefile_spec.rb
139
137
  - spec/noir/command/new/note_spec.rb
140
138
  - spec/noir/command/new_spec.rb
139
+ - spec/noir/command/summarize/note/weekly_spec.rb
140
+ - spec/noir/command/summarize/note_spec.rb
141
+ - spec/noir/command/summarize_spec.rb
141
142
  - spec/noir/command_spec.rb
142
143
  - spec/noir/executer_spec.rb
143
144
  - spec/noir/noir/base/command_spec.rb
@@ -195,6 +196,9 @@ test_files:
195
196
  - spec/noir/command/new/makefile_spec.rb
196
197
  - spec/noir/command/new/note_spec.rb
197
198
  - spec/noir/command/new_spec.rb
199
+ - spec/noir/command/summarize/note/weekly_spec.rb
200
+ - spec/noir/command/summarize/note_spec.rb
201
+ - spec/noir/command/summarize_spec.rb
198
202
  - spec/noir/command_spec.rb
199
203
  - spec/noir/executer_spec.rb
200
204
  - spec/noir/noir/base/command_spec.rb
@@ -1,10 +0,0 @@
1
- class Noir::Command::Edit::WeeklyReport::Friday < Noir::Base::TerminalCommand
2
- @description = 'edit weekly report separated by friday'
3
-
4
- class << self
5
- def execute *args
6
- week_diff = args.first.to_i || 0
7
- Noir::Command::Edit::WeeklyReport.edit_report :friday, week_diff
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- class Noir::Command::Edit::WeeklyReport::Monday < Noir::Base::TerminalCommand
2
- @description = 'edit weekly report separated by monday'
3
-
4
- class << self
5
- def execute *args
6
- week_diff = args.first.to_i || 0
7
- Noir::Command::Edit::WeeklyReport.edit_report :monday, week_diff
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- class Noir::Command::Edit::WeeklyReport::Saturday < Noir::Base::TerminalCommand
2
- @description = 'edit weekly report separated by saturday'
3
-
4
- class << self
5
- def execute *args
6
- week_diff = args.first.to_i || 0
7
- Noir::Command::Edit::WeeklyReport.edit_report :saturday, week_diff
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- class Noir::Command::Edit::WeeklyReport::Sunday < Noir::Base::TerminalCommand
2
- @description = 'edit weekly report separated by sunday'
3
-
4
- class << self
5
- def execute *args
6
- week_diff = args.first.to_i || 0
7
- Noir::Command::Edit::WeeklyReport.edit_report :sunday, week_diff
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- class Noir::Command::Edit::WeeklyReport::Thursday < Noir::Base::TerminalCommand
2
- @description = 'edit weekly report separated by thursday'
3
-
4
- class << self
5
- def execute *args
6
- week_diff = args.first.to_i || 0
7
- Noir::Command::Edit::WeeklyReport.edit_report :thursday, week_diff
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- class Noir::Command::Edit::WeeklyReport::Tuesday < Noir::Base::TerminalCommand
2
- @description = 'edit weekly report separated by tuesday'
3
-
4
- class << self
5
- def execute *args
6
- week_diff = args.first.to_i || 0
7
- Noir::Command::Edit::WeeklyReport.edit_report :tuesday, week_diff
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- class Noir::Command::Edit::WeeklyReport::Wednesday < Noir::Base::TerminalCommand
2
- @description = 'edit weekly report separated by wednesday'
3
-
4
- class << self
5
- def execute *args
6
- week_diff = args.first.to_i || 0
7
- Noir::Command::Edit::WeeklyReport.edit_report :wednesday, week_diff
8
- end
9
- end
10
- end