Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 373
- Log:
Initial import of Radiant 0.9.1, which is now packaged as a gem. This is an
import of the tagged 0.9.1 source checked out from GitHub, which isn't quite
the same as the gem distribution - but it doesn't seem to be available in an
archived form and the installed gem already has modifications, so this is
the closest I can get.
- Author:
- rool
- Date:
- Mon Mar 21 13:40:05 +0000 2011
- Size:
- 2169 Bytes
1 | #!/usr/local/bin/ruby -w |
2 | |
3 | # basic_usage.rb |
4 | # |
5 | # Created by James Edward Gray II on 2005-04-28. |
6 | # Copyright 2005 Gray Productions. All rights reserved. |
7 | |
8 | require "rubygems" |
9 | require "highline/import" |
10 | require "yaml" |
11 | |
12 | contacts = [ ] |
13 | |
14 | class NameClass |
15 | def self.parse( string ) |
16 | if string =~ /^\s*(\w+),\s*(\w+)\s*$/ |
17 | self.new($2, $1) |
18 | else |
19 | raise ArgumentError, "Invalid name format." |
20 | end |
21 | end |
22 | |
23 | def initialize(first, last) |
24 | @first, @last = first, last |
25 | end |
26 | |
27 | attr_reader :first, :last |
28 | end |
29 | |
30 | begin |
31 | entry = Hash.new |
32 | |
33 | # basic output |
34 | say("Enter a contact:") |
35 | |
36 | # basic input |
37 | entry[:name] = ask("Name? (last, first) ", NameClass) do |q| |
38 | q.validate = /\A\w+, ?\w+\Z/ |
39 | end |
40 | entry[:company] = ask("Company? ") { |q| q.default = "none" } |
41 | entry[:address] = ask("Address? ") |
42 | entry[:city] = ask("City? ") |
43 | entry[:state] = ask("State? ") do |q| |
44 | q.case = :up |
45 | q.validate = /\A[A-Z]{2}\Z/ |
46 | end |
47 | entry[:zip] = ask("Zip? ") do |q| |
48 | q.validate = /\A\d{5}(?:-?\d{4})?\Z/ |
49 | end |
50 | entry[:phone] = ask( "Phone? ", |
51 | lambda { |p| p.delete("^0-9"). |
52 | sub(/\A(\d{3})/, '(\1) '). |
53 | sub(/(\d{4})\Z/, '-\1') } ) do |q| |
54 | q.validate = lambda { |p| p.delete("^0-9").length == 10 } |
55 | q.responses[:not_valid] = "Enter a phone numer with area code." |
56 | end |
57 | entry[:age] = ask("Age? ", Integer) { |q| q.in = 0..105 } |
58 | entry[:birthday] = ask("Birthday? ", Date) |
59 | entry[:interests] = ask( "Interests? (comma separated list) ", |
60 | lambda { |str| str.split(/,\s*/) } ) |
61 | entry[:description] = ask("Enter a description for this contact.") do |q| |
62 | q.whitespace = :strip_and_collapse |
63 | end |
64 | |
65 | contacts << entry |
66 | # shortcut for yes and no questions |
67 | end while agree("Enter another contact? ", true) |
68 | |
69 | if agree("Save these contacts? ", true) |
70 | file_name = ask("Enter a file name: ") do |q| |
71 | q.validate = /\A\w+\Z/ |
72 | q.confirm = true |
73 | end |
74 | File.open("#{file_name}.yaml", "w") { |file| YAML.dump(contacts, file) } |
75 | end |