Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Templates: extract array of hashes #45

Open
zverok opened this issue Dec 14, 2015 · 1 comment
Open

Templates: extract array of hashes #45

zverok opened this issue Dec 14, 2015 · 1 comment
Milestone

Comments

@zverok
Copy link
Contributor

zverok commented Dec 14, 2015

For example, in country infoboxes is common pattern:

...
|leader_title1      = [[President of Israel|President]]
|leader_name1       = [[Reuven Rivlin]]
|leader_title2      = [[Prime Minister of Israel|Prime Minister]]
|leader_name2       = [[Benjamin Netanyahu]]
...
|established_event1       = [[Israeli Declaration of Independence|Declared]]
|established_date1        = 14 May 1948
|established_event2       = [[Israel, Palestine, and the United Nations|Recognition]]
|established_date2        = 1 May 1949
...

Best solution should somewhat like that:

page.infobox.array_of_hashes('established') 
# => [
#  {
#    event: Wikilink(Declared, link: Israeli Declaration of Independence), 
#    date: '14 May 1948',
#  },
#  {
#    event: Wikilink(Recognition, link: Israel, Palestine, and the United Nations),
#    date: '1 May 1949'
#  }
#]

page.infobox.array_of_hashes('leader')
# => [
#  {
#    title: Wikilink(President, President of Israel),
#    name: Wikilink(Reuven Rivlin)
#  },
#  {
#    title: Wikilink(Prime Minister, Prime Minister of Israel),
#    name: Wikilink(Benjamin Netanyahu)
#  }
#]
@zverok
Copy link
Contributor Author

zverok commented Dec 14, 2015

Similar (or the same) task:

# source:
# |area_rank = 120th
# |area_magnitude = 1 E10
# |area_km2 = 69,420
# |area_sq_mi = 26,911

# code:
page.infobox.fetch_all('area')
# => {
#   rank: "120th",
#   magnitude: "1 E10",
#   km2: "69,420",
#   sq_mi: "26,911"
# }

@zverok zverok modified the milestone: 0.3.0 Jan 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant