GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - mark/string_formatter: StringFormatter: a library for defining custom strf-style methods for your objects

BranchesTags
Open more actions menu

Latest commit

 

History

27 Commits
27 Commits

Folders and files

NameName
Last commit message
Last commit date
lib
lib
 
 
spec
spec
 
 
.gitignore
.gitignore
 
 
README
README
 
 
Rakefile
Rakefile
 
 
string_formatter.gemspec
string_formatter.gemspec
 
 

Repository files navigation

StringFormatter is a method for defining custom strf-style methods for your object.

* string_formatter require Ruby 1.9 or higher *

Example:

class PersonFormatter < StringFormatter
  
  f { |p| p.first_name }
  F { |p| p.first_name.upcase }
  l { |p| p.last_name  }

  punctuation

  pipe { |p| 'PIPE' }
  
end

class UpcaseFormatter < StringFormatter
  
  f { |p| p.first_name.upcase }
  l { |p| p.last_name.upcase  }
  
end

class Person
  attr_accessor :first_name, :last_name

  define_format_string :strf,   :with => PersonFormatter
  define_format_string :strfup, :with => UpcaseFormatter
  
  def initialize(*names)
    @first_name, @last_name = names
  end
  
end

p = Person.new("Bob", "Smith")

p.strf('%l, %f %|')
# => "Smith, Bob PIPE"

p.strfup('%l, %f')
# => "SMITH, BOB"

You can define definitions for lower case characters, upper case characters, and punctuation marks.  The method for lower and upper case characters is the character itself, and the punctuation marks have specific names for each.

About

StringFormatter: a library for defining custom strf-style methods for your objects

Resources

Readme
Activity

Stars

5 stars

Watchers

2 watching

Forks

1 fork
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.