Class: Lesstrack
- Inherits:
-
Object
- Object
- Lesstrack
- Defined in:
- lib/lesstrack.rb
Constant Summary collapse
- VERSION =
:stopdoc:
'1.0.0'
- LIBPATH =
::File.(::File.dirname(__FILE__)) + ::File::SEPARATOR
- PATH =
::File.dirname(LIBPATH) + ::File::SEPARATOR
Class Method Summary collapse
-
.libpath(*args) ⇒ Object
Returns the library path for the module.
- .password ⇒ Object
-
.path(*args) ⇒ Object
Returns the lpath for the module.
-
.require_all_libs_relative_to(fname, dir = nil) ⇒ Object
Utility method used to require all files ending in .rb that lie in the directory below this file that has the same name as the filename passed in.
- .username ⇒ Object
-
.version ⇒ Object
Returns the version string for the library.
Instance Method Summary collapse
- #config(reload = false) ⇒ Object
-
#initialize ⇒ Lesstrack
constructor
A new instance of Lesstrack.
-
#punch(reload = false) ⇒ Object
load the punch.yml file.
- #repeat?(punch_item, clock_punches) ⇒ Boolean
- #run ⇒ Object
Constructor Details
#initialize ⇒ Lesstrack
Returns a new instance of Lesstrack.
7 8 9 10 |
# File 'lib/lesstrack.rb', line 7 def initialize @punch = nil @config = nil end |
Class Method Details
.libpath(*args) ⇒ Object
Returns the library path for the module. If any arguments are given, they will be joined to the end of the libray path using File.join
.
81 82 83 |
# File 'lib/lesstrack.rb', line 81 def self.libpath( *args ) args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten) end |
.password ⇒ Object
16 17 18 |
# File 'lib/lesstrack.rb', line 16 def self.password @@password ||= nil end |
.path(*args) ⇒ Object
Returns the lpath for the module. If any arguments are given, they will be joined to the end of the path using File.join
.
89 90 91 |
# File 'lib/lesstrack.rb', line 89 def self.path( *args ) args.empty? ? PATH : ::File.join(PATH, args.flatten) end |
.require_all_libs_relative_to(fname, dir = nil) ⇒ Object
Utility method used to require all files ending in .rb that lie in the directory below this file that has the same name as the filename passed in. Optionally, a specific directory name can be passed in such that the filename does not have to be equivalent to the directory.
98 99 100 101 102 103 104 |
# File 'lib/lesstrack.rb', line 98 def self.require_all_libs_relative_to( fname, dir = nil ) dir ||= ::File.basename(fname, '.*') search_me = ::File.( ::File.join(::File.dirname(fname), dir, '**', '*.rb')) Dir.glob(search_me).sort.each {|rb| require rb} end |
.username ⇒ Object
12 13 14 |
# File 'lib/lesstrack.rb', line 12 def self.username @@username ||= nil end |
.version ⇒ Object
Returns the version string for the library.
73 74 75 |
# File 'lib/lesstrack.rb', line 73 def self.version VERSION end |
Instance Method Details
#config(reload = false) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/lesstrack.rb', line 29 def config(reload = false) if reload || @config.nil? @config = YAML.load_file(File.join(ENV['HOME'], '.lesstrack.yml')) @@username = config['username'] @@password = config['password'] end return @config end |
#punch(reload = false) ⇒ Object
load the punch.yml file
21 22 23 24 25 26 27 |
# File 'lib/lesstrack.rb', line 21 def punch(reload = false) if reload || @punch.nil? return @punch = YAML.load_file(File.join(ENV['HOME'], '.punch.yml')) else return @punch end end |
#repeat?(punch_item, clock_punches) ⇒ Boolean
55 56 57 58 59 |
# File 'lib/lesstrack.rb', line 55 def repeat?(punch_item, clock_punches) clock_punches.detect do |clock_punch| punch_item["out"] == clock_punch.ends_at && punch_item["in"] == clock_punch.starts_at end end |
#run ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/lesstrack.rb', line 39 def run config['project_mapping'].each do |key, project_id| clock_punches = ClockPunch.find(:all, :params => {:project_id => project_id}) punch[key].each do |punch_item| next if repeat?(punch_item, clock_punches) check_repeat(punch_item, clock_punches) notes = punch_item["log"].clone notes.delete_if do |value| value.match(/^punch (in|out)/) end r = RestClient.post("https://#{config['username']}:#{config['password']}@lesstimespent.com/projects/#{project_id}/clock_punches.xml", :clock_punch => {:starts_at => punch_item["in"], :ends_at => punch_item["out"], :note => notes.join('\n')} ) end end end |