Class: GitFit::Source::Base
- Inherits:
-
Object
- Object
- GitFit::Source::Base
- Defined in:
- lib/git_fit/source/base.rb
Instance Attribute Summary collapse
-
#progress_reported ⇒ Object
readonly
Returns the value of attribute progress_reported.
Instance Method Summary collapse
- #before_call ⇒ Object
- #build_progress_info(attrs) ⇒ Object
- #call ⇒ Object
-
#initialize(config:, db:, activity_filter: nil, privacy: nil, time_budget: nil) ⇒ Base
constructor
A new instance of Base.
- #pending_ids ⇒ Object
- #process_one(pending) ⇒ Object
Constructor Details
#initialize(config:, db:, activity_filter: nil, privacy: nil, time_budget: nil) ⇒ Base
Returns a new instance of Base.
6 7 8 9 10 11 12 13 14 |
# File 'lib/git_fit/source/base.rb', line 6 def initialize(config:, db:, activity_filter: nil, privacy: nil, time_budget: nil) @config = config @db = db @activity_filter = activity_filter @privacy = privacy @time_budget = time_budget @start_time = nil @progress_reported = false end |
Instance Attribute Details
#progress_reported ⇒ Object (readonly)
Returns the value of attribute progress_reported.
16 17 18 |
# File 'lib/git_fit/source/base.rb', line 16 def progress_reported @progress_reported end |
Instance Method Details
#before_call ⇒ Object
33 34 35 36 |
# File 'lib/git_fit/source/base.rb', line 33 def before_call @start_time = Time.now true end |
#build_progress_info(attrs) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/git_fit/source/base.rb', line 46 def build_progress_info(attrs) parts = [] sd = attrs["start_date"] || attrs[:start_date] if sd d = Date.parse(sd.to_s) rescue nil if d date_str = d.year == Date.today.year ? d.strftime("%m-%d") : d.strftime("%Y-%m-%d") parts << date_str end end type = attrs["sport_category"] || attrs[:sport_category] parts << type if type dist = attrs["distance"] || attrs[:distance] if dist && dist.to_f > 0 parts << "#{format('%.1f', dist.to_f / 1000)}km" end source = attrs["source"] || attrs[:source] || source_label name = attrs["name"] || attrs[:name] display_name = name.to_s.strip display_name = "#{source} Activity" if display_name.empty? chars = display_name.chars display_name = chars.first(30).join + "…" if chars.size > 30 parts << display_name parts.join(" | ") unless parts.empty? end |
#call ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/git_fit/source/base.rb', line 18 def call return 0 unless before_call return 0 unless respond_to?(:authenticate) ? authenticate : true ids = pending_ids return 0 if ids.nil? || ids.empty? total = ids.size count = 0 ids.filter_map do |p| r = process_one(p) count += 1 report_progress(count, total, build_progress_info(r)) if r r end.size end |
#pending_ids ⇒ Object
38 39 40 |
# File 'lib/git_fit/source/base.rb', line 38 def pending_ids raise NotImplementedError end |
#process_one(pending) ⇒ Object
42 43 44 |
# File 'lib/git_fit/source/base.rb', line 42 def process_one(pending) raise NotImplementedError end |