Module: Archsight::Helpers::Formatting

Included in:
Archsight::Helpers
Defined in:
lib/archsight/helpers/formatting.rb

Overview

Formatting provides string and number formatting utilities

Constant Summary collapse

AI_ESTIMATE_CONFIG =

AI-adjusted project estimate configuration Source values stored separately for easy adjustment

{
  cocomo_salary: 150_000,      # COCOMO assumes US salary in USD
  target_salary: 80_000,       # Target salary in EUR
  ai_cost_multiplier: 3.0,     # AI productivity boost for cost
  ai_schedule_multiplier: 2.5, # AI productivity boost for schedule
  ai_team_multiplier: 3.0      # AI productivity boost for team size
}.freeze

Class Method Summary collapse

Class Method Details

.ai_adjusted_estimate(type, value) ⇒ Numeric?

Apply AI adjustment factors to project estimates

Parameters:

  • type (Symbol)

    :cost, :schedule, or :team

  • value (Numeric, nil)

    Raw estimate value

Returns:

  • (Numeric, nil)

    Adjusted value



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/archsight/helpers/formatting.rb', line 36

def ai_adjusted_estimate(type, value)
  return nil if value.nil?

  cfg = AI_ESTIMATE_CONFIG
  salary_ratio = cfg[:target_salary].to_f / cfg[:cocomo_salary]

  adjusted = case type
             when :cost
               value.to_f * salary_ratio / cfg[:ai_cost_multiplier]
             when :schedule
               value.to_f / cfg[:ai_schedule_multiplier]
             when :team
               (value.to_f / cfg[:ai_team_multiplier]).ceil
             else
               raise ArgumentError, "Unknown estimate type: #{type}"
             end

  type == :team ? adjusted.to_i : adjusted
end

.classify(val) ⇒ Object

Convert string to class name format



10
11
12
# File 'lib/archsight/helpers/formatting.rb', line 10

def classify(val)
  val.to_s.split("-").map(&:capitalize).join
end

.http_git(repo_url) ⇒ Object

Convert git URL to HTTPS URL



57
58
59
60
61
# File 'lib/archsight/helpers/formatting.rb', line 57

def http_git(repo_url)
  repo_url.gsub(/.git$/, "")
          .gsub(":", "/")
          .gsub("git@", "https://")
end

.number_with_delimiter(num) ⇒ Object

Format number with thousands delimiter



64
65
66
# File 'lib/archsight/helpers/formatting.rb', line 64

def number_with_delimiter(num)
  num.to_s.reverse.scan(/\d{1,3}/).join(",").reverse
end

.time_ago(timestamp) ⇒ Object

Convert timestamp to human-readable relative time



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/archsight/helpers/formatting.rb', line 69

def time_ago(timestamp)
  return nil unless timestamp

  time = timestamp.is_a?(Time) ? timestamp : Time.parse(timestamp.to_s)
  seconds = (Time.now - time).to_i

  units = [
    [60, "second"],
    [60, "minute"],
    [24, "hour"],
    [7, "day"],
    [4, "week"],
    [12, "month"],
    [Float::INFINITY, "year"]
  ]

  value = seconds
  units.each do |divisor, unit|
    return "just now" if unit == "second" && value < 10
    return "#{value} #{unit}#{"s" if value != 1} ago" if value < divisor

    value /= divisor
  end
end

.to_euro(num) ⇒ Object

Format number as euro currency



15
16
17
18
19
20
# File 'lib/archsight/helpers/formatting.rb', line 15

def to_euro(num)
  rounded = (num * 100).round / 100.0
  parts = format("%.2f", rounded).split(".")
  parts[0] = parts[0].reverse.scan(/\d{1,3}/).join(",").reverse
  "#{parts.join(".")}"
end