What kind of data structure is this? - ruby

I am pulling recent commits from github and trying to parse it using ruby. I know that I can parse it manually but I wanted to see if there was some package that could turn this into a hash or another data structure.
commits:
- parents:
- id: 202fb79e8686ee127fe49497c979cfc9c9d985d5
author:
name: This guy
login: tguy
email: tguy#tguy.com
url: a url
id: e466354edb31f243899051e2119f4ce72bafd5f3
committed_date: "2010-07-19T13:44:43-07:00"
authored_date: "2010-07-19T13:33:26-07:00"
message: |-
message
- parents:
- id: c3c349ec3e9a3990cac4d256c308b18fd35d9606
author:
name: Other Guy
login: oguy
email: oguy#gmail.com
url: another url
id: 202fb79e8686ee127fe49497c979cfc9c9d985d5
committed_date: "2010-07-19T13:44:11-07:00"
authored_date: "2010-07-19T13:44:11-07:00"
message: this is another message

This is YAML http://ruby-doc.org/core/classes/YAML.html. You can do something like obj = YAML::load yaml_string (and a require 'yaml' at the top of your file, its in the standard libs), and then access it like a nested hash.
YAML is basically used in the ruby world the way people use XML in the java/c# worlds.

Looks like YAML to me. There are parsers for a lot of languages. For example, with the YAML library included with Ruby:
data = <<HERE
commits:
- parents:
- id: 202fb79e8686ee127fe49497c979cfc9c9d985d5
author:
name: This guy
login: tguy
email: tguy#tguy.com
url: a url
id: e466354edb31f243899051e2119f4ce72bafd5f3
committed_date: "2010-07-19T13:44:43-07:00"
authored_date: "2010-07-19T13:33:26-07:00"
message: |-
message
- parents:
- id: c3c349ec3e9a3990cac4d256c308b18fd35d9606
author:
name: Other Guy
login: oguy
email: oguy#gmail.com
url: another url
id: 202fb79e8686ee127fe49497c979cfc9c9d985d5
committed_date: "2010-07-19T13:44:11-07:00"
authored_date: "2010-07-19T13:44:11-07:00"
message: this is another message
HERE
pp YAML.load data
It prints:
{"commits"=>
[{"author"=>{"name"=>"This guy", "login"=>"tguy", "email"=>"tguy#tguy.com"},
"parents"=>[{"id"=>"202fb79e8686ee127fe49497c979cfc9c9d985d5"}],
"url"=>"a url",
"id"=>"e466354edb31f243899051e2119f4ce72bafd5f3",
"committed_date"=>"2010-07-19T13:44:43-07:00",
"authored_date"=>"2010-07-19T13:33:26-07:00",
"message"=>"message"},
{"author"=>
{"name"=>"Other Guy", "login"=>"oguy", "email"=>"oguy#gmail.com"},
"parents"=>[{"id"=>"c3c349ec3e9a3990cac4d256c308b18fd35d9606"}],
"url"=>"another url",
"id"=>"202fb79e8686ee127fe49497c979cfc9c9d985d5",
"committed_date"=>"2010-07-19T13:44:11-07:00",
"authored_date"=>"2010-07-19T13:44:11-07:00",
"message"=>"this is another message"}]}

This format is YAML, but you can get the same information in XML or JSON, see General API Information. I'm sure there are libraries to parse those formats in Ruby.

Although this isn't exactly what you're looking for, here's some more info on pulling commits. http://develop.github.com/p/commits.html. Otherwise, I think you may just need to manually parse it.

Related

How is $id and $ref values are used in device tree yaml binding file? and can I see it?

This has been a question I had for a long time.
I started to read https://docs.kernel.org/devicetree/bindings/writing-schema.html but it's hard to understand.
For example in linux-5.15.68, the file Documentation/devicetree/bindings/pci/snps,dw-pcie.yaml starts like this.
# SPDX-License-Identifier: GPL-2.0
%YAML 1.2
---
$id: http://devicetree.org/schemas/pci/snps,dw-pcie.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#
title: Synopsys DesignWare PCIe interface
maintainers:
- Jingoo Han <jingoohan1#gmail.com>
- Gustavo Pimentel <gustavo.pimentel#synopsys.com>
description: |
Synopsys DesignWare PCIe host controller
allOf:
- $ref: /schemas/pci/pci-bus.yaml#
properties:
compatible:
anyOf:
- {}
- const: snps,dw-pcie
How is the URI $id and $scmema used? and if I want to browse the file, how can I do it?
When I put http://devicetree.org/schemas/pci/snps,dw-pcie.yaml the browser says 'These are not the schemas you are looking for.'.

YAMLSyntaxError: Failed to resolve SEQ_ITEM node here at line X, column Y:

I'm getting this error when trying to run Netlify CMS
Error loading the CMS configuration
Config Errors:
YAMLSyntaxError: Failed to resolve SEQ_ITEM node here at line 10, column 1:
- name: Posts
^^^^^^^^^^^^^^…
Check your config.yml file.
I have checked the syntax and tried different syntax but I still get the same error for somewhere in the config.yml document.
This is the troubled config.yml document:
backend:
name: git-gateway
branch: master
media_folder: src/assets/images
media_library:
name: uploads
collections:
- name: Posts
label: Posts
create: true
folder: "/articles"
slug: articles/{{slug}}
fields:
- {label: Title, name: title, widget: string}
- {label: Publish Date, name: date, widget: datetime}
- {label: Featured Image, name: cover_image, widget: image}
- {label: Body, name: body, widget: markdown}
Here is a link to the files that I am getting the errors from https://drive.google.com/file/d/1OJPKJRgCljxAG5UuUxXkBPPNoUcyJe48/view?usp=sharing
The file you linked uses tabs for indentation. YAML uses spaces, see the spec:
In general, indentation is defined as a zero or more space characters at the start of a line.
To maintain portability, tab characters must not be used in indentation, since different systems treat tabs differently.
You need to convert the tabs to spaces.

How to use $ref for tags between files

I am using Open API 3.0, in A.yaml
# something above
tags:
- name: user
description: Operations about user
- name: user_stuff
description: API for user stuff
- name: another_user_stuff
description: API for another user stuff
# something below
Then, in B.yaml, I want to make reference to the tags in A.yaml, for example the tag of user. Suppose in B.yaml, we have
post:
tags:
$ref: <What are the things should be here?>
summary: do somthing
description: "do something"
requestBody:
# bla bla bla
required: true
responses:
"200":
description: uccessfully
x-swagger-router-controller: B
How can I make a reference from B.yaml to A.yaml?
The tags keyword does not support $ref. All tags must be defined inline.
# B.yaml
tags:
- name: foo
description: Operations to manage Foos.
paths:
/something:
post:
tags:
- foo
- bar
That said, you don't have to define tags in the global tags section in order to use them in operations. The global tags section is used only to define extra tag metadata, such as descriptions and externalDocs, or the tag order in documentation tools.

#Misc equivalent in CSL YAML

I want to migrate from my BiBTeX record:
#Misc{ propi-records-atletisme-en,
author = "Bordoy, Xavier",
title = "Athletics records",
url = "http://somenxavier.xyz/public/blog/fitxers/athletics-races.pdf",
year = "2016"
}
to CSL YAML:
references:
- type: "Misc"
id: "propi-records-atletisme-en"
author:
- family: "Bordoy"
given: "Xavier"
title: "Athletics records"
issued:
year: "2016"
URL: "http://somenxavier.xyz/bitacola/blog/athletics-races.pdf"
But when I compile it to pandoc, I get:
Error parsing references: 'Misc' is not a valid reference type
So, what is equivalent to #Misc?
CSL has more item types than standard bibtex (here's a full list), so there's no single #misc equivalent, but for webpages as in your example, you'd simply use type: "webpage"

Ruby Mechanize Find Form w/ No Name

I'm pointing a Ruby solution at a form. I have the page, but I don't know how to target the form because it has no name.
Here's the (beginning) form inside the page parsed by Mechanize:
{forms
#<Mechanize::Form
{name nil}
{method "GET"}
{action
"/app/ccc/srch/srch.do;jsessionid=00003bU0tdqSPfRfiG1f9n8g0gL:17e5e02re"}
{fields
[hidden:0x3ff0ed0d5f98 type: hidden name: lang value: eng]
[hidden:0x3ff0ed0d5cdc type: hidden name: profileId value: ]
[hidden:0x3ff0ed0d5818 type: hidden name: prtl value: 1]
I read on a python comment that I can use something that counts the forms by number (0 = first) but I tried using page.select_form(nr=0) and it didn't work.
Any advice appreciated.
Cheers
Just found it.
CCCform = page.form()
Works like a charm. I don't know how to get the second form on a potential page.
Cheers

Resources