Skip to content

Instantly share code, notes, and snippets.

@lmullen
Created May 2, 2012 21:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lmullen/2580742 to your computer and use it in GitHub Desktop.
Save lmullen/2580742 to your computer and use it in GitHub Desktop.
Modeling historical events in YAML and Ruby
# A model of a convert's life
---
name-last : Brownson
name-first : Orestes Augustus
born : 1803-09-16
died : 1876-04-17
birth-religion : Congregationalism
conversions :
- origin-religion : Congregationalism
destination-religion : Presbyterianism
date : 1822
ritual : church membership
citation : ANB
notes : >
Brownson's change to congregationalism was more denominational
switching than a change in conscience.
- origin-religion : Presbyterianism
destination-religion : Universalism
date : 1826
ritual : ordination
location : "Jaffrey, New Hampshire"
citation : ANB
notes : >
"He would later refer to his years in this fold as 'the most
anti-Christian period of my life'" (ANB).
Brownson was editor of _The Gospel Advocate and Impartial
Investigator_, a Universalist publication.
- origin-religion : Universalism
destination-religion : Unitarianism
ritual : further research
location : "Walpole, New Hampshire"
citation : ANB
notes : >
Brownson spent some time at Brook Farm, which prepared him for
Transcendentalism
- origin-religion : Unitarianism and Transcendentalism
destination-religion : Catholicism
date : 1844-10-19
ritual : baptism
citation : ANB
notes : >
Brownson studied after his conversion with a Sulpician priest.
source :
- @carey_orestes_2004
- American National Biography
comments : >
This is a minimal example of what a model of a convert might look
like. The historical data is hastily gathered, so only the model is
of interest here.
N.B. I would like to replace the citations with BibTeX keys.
...
#!/usr/bin/env ruby
# A proof-of-concept script that outputs some simple data from YAML
# files modeling conversions
#
# Author:: Lincoln Mullen (lincoln@lincolnmullen.com)
require 'yaml'
# This class loads data from YAML files, and outputs some values
class Converts
attr_accessor :files, :data
def initialize (files = nil, data = nil)
@files = files
@data = Hash.new
if @files.nil?
puts "You didn't pass me any files."
elsif @files.respond_to?("each")
# walk through the array of files, creating a hash with the
# file name as the key and the file data as the value
@files.each do |file|
@data[file] = YAML.load_file( file )
end
end
end
# output the hash we can see what we're working with
def display_raw
puts "\nThis is the raw data we have loaded:"
p( @data )
end
# walk through the hash, outputting the names of each person
def display_names
puts "\nThese people converted:"
@data.each_key do |key|
puts " - #{@data[key]["name-first"]} #{@data[key]["name-last"]}"
end
end
# walk through the hash, outputting the names and conversions of
# each person
def display_conversions
puts "\nWe know about these conversions:"
@data.each_key do |key|
puts " - #{@data[key]["name-first"]} #{@data[key]["name-last"]}:"
# each person has an array of conversions (even if there is
# only one conversion)
@data[key]["conversions"].each { |conversion|
puts " + From #{conversion["origin-religion"]} to #{conversion["destination-religion"]} by #{conversion["ritual"]} in #{conversion["date"]}."
}
end
end
end
# get sample data by loading every YAML file in the directory
puts "Let's load all the YAML files in this directory:"
puts Dir.glob( '*.yml').join(', ')
c = Converts.new(Dir.glob('*.yml'))
# call the methods to display the names and conversions
c.display_names
c.display_conversions
Let's load all the YAML files in this directory:
brownson-orestes.yml, wharton-charles.yml
These people converted:
- Charles Wharton
- Orestes Augustus Brownson
We know about these conversions:
- Charles Wharton:
+ From Catholicism to Church of England by conformity in .
- Orestes Augustus Brownson:
+ From Congregationalism to Presbyterianism by church membership in 1822.
+ From Presbyterianism to Universalism by ordination in 1826.
+ From Universalism to Unitarianism by further research in .
+ From Unitarianism and Transcendentalism to Catholicism by baptism in 1844-10-19.
# a YAML model of a convert's life
---
name-last : Wharton
name-first : Charles
born :
died :
birth-religion :
conversions :
- origin-religion : Catholicism
origin-clergy : Jesuit
destination-religion : Church of England
date :
ritual : conformity
location : England
citation : "@carroll_john_1976, 1:xlviii"
notes : >
Charles Wharton was "a former Jesuit who had conformed to the
Church of England and in 1784 was serving as a clergyman of the
recently formed Protestant Episcopal Church."
source :
- "@carroll_john_1976, 1:xlviii"
comments : >
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment