Module: Hecks::Forms::Humanize
- Defined in:
- lib/hecks/forms/field_shape.rb
Class Method Summary collapse
-
.breadcrumb(path) ⇒ Object
The full dotted path, each segment humanized and joined with " → " for a fieldset legend spanning more than one hop ("Amount → Cents") — a group's own legend, not a leaf's label.
-
.label(text) ⇒ Object
"given" -> "Given", "daily_limit" -> "Daily limit", "end_to_end" -> "End to end" — the label a plain reader wants, not the wire spelling.
Class Method Details
.breadcrumb(path) ⇒ Object
The full dotted path, each segment humanized and joined with " → " for a fieldset legend spanning more than one hop ("Amount → Cents") — a group's own legend, not a leaf's label.
46 47 48 |
# File 'lib/hecks/forms/field_shape.rb', line 46 def self.(path) path.to_s.split(".").map { |part| label(part) }.join(" → ") end |
.label(text) ⇒ Object
"given" -> "Given", "daily_limit" -> "Daily limit", "end_to_end" -> "End to end" — the label a plain reader wants, not the wire spelling.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/hecks/forms/field_shape.rb', line 30 def self.label(text) # Split on "." FIRST, alone, to take only the last path segment — # "daily_limit" is one segment (the underscore is a word break # inside it, not a path hop) and must keep both its words; only a # genuinely dotted path ("amount.cents") drops everything before # the last ".". segment = text.to_s.split(".").last.to_s words = segment.split("_") return segment if words.empty? ([words.first.capitalize] + words.drop(1)).join(" ") end |